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