1 | -- loadstring(game:HttpGet("https://pastecode.dev/raw/isz2p5ce/paste1.txt"))() |
2 | |
3 | local detectionRadius = 18 |
4 | local character = game.Players.LocalPlayer.Character |
5 | |
6 | -- Function to find the closest player |
7 | local function findClosestPlayer() |
8 | local closestPlayer = nil |
9 | local closestDistance = math.huge |
10 | |
11 | for _, player in pairs(game.Players:GetPlayers()) do |
12 | if player ~= game.Players.LocalPlayer and player.Character and player.Character:FindFirstChild("Humanoid") then |
13 | local humanoid = player.Character.Humanoid |
14 | if humanoid.Health > 0 then |
15 | local distance = (humanoid.Parent.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude |
16 | if distance < detectionRadius and distance < closestDistance then |
17 | closestPlayer = player |
18 | closestDistance = distance |
19 | end |
20 | end |
21 | end |
22 | end |
23 | |
24 | return closestPlayer |
25 | end |
26 | |
27 | -- Function to make your character look at the closest player |
28 | local function lookAtClosestPlayer() |
29 | local closestPlayer = findClosestPlayer() |
30 | |
31 | if closestPlayer then |
32 | local direction = (closestPlayer.Character.HumanoidRootPart.Position - character.HumanoidRootPart.Position).unit |
33 | |
34 | -- Introduce a rotation to face slightly to the right (adjust the angle as needed) |
35 | local rotationAngle = math.rad(23) -- Adjust this value for less rotation or in the opposite direction |
36 | |
37 | local rotatedDirection = CFrame.Angles(0, rotationAngle, 0) * direction |
38 | |
39 | local lookVector = Vector3.new(rotatedDirection.X, 0, rotatedDirection.Z) |
40 | |
41 | -- Update the CFrame of the HumanoidRootPart |
42 | character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position + lookVector) |
43 | end |
44 | end |
45 | |
46 | -- Connect to RenderStepped to continuously update the look at the closest player |
47 | game:GetService("RunService").RenderStepped:Connect(function() |
48 | lookAtClosestPlayer() |
49 | end) |