Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- look at nearest torso
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local Mouse = LocalPlayer:GetMouse()
- function GetNearestPlayer()
- local NearestPlayer = nil
- local NearestDistance = math.huge
- for _, Player in pairs(Players:GetPlayers()) do
- if Player ~= LocalPlayer and Player.Character and Player.Character:FindFirstChild("Torso") then
- local Distance = (Player.Character.Torso.Position - LocalPlayer.Character.Torso.Position).magnitude
- if Distance < NearestDistance then
- NearestDistance = Distance
- NearestPlayer = Player
- end
- end
- end
- return NearestPlayer
- end
- function AimAt(Player)
- if Player then
- local Target = Player.Character.Torso.Position + Vector3.new(0, 1, 0)
- local MouseVector = (Target - workspace.CurrentCamera.CFrame.p).unit
- local MouseLook = CFrame.new(Mouse.Hit.p, Mouse.Hit.p + MouseVector)
- workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:lerp(MouseLook, 0.1)
- end
- end
- function examP()
- local NearestPlayer = GetNearestPlayer()
- AimAt(NearestPlayer)
- end
- game:GetService("RunService").RenderStepped:Connect(examP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement