Advertisement
scriptingtales

AimThingerRoblox

Jun 2nd, 2023 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. -- look at nearest torso
  2.  
  3. local Players = game:GetService("Players")
  4. local LocalPlayer = Players.LocalPlayer
  5. local Mouse = LocalPlayer:GetMouse()
  6.  
  7. function GetNearestPlayer()
  8.     local NearestPlayer = nil
  9.     local NearestDistance = math.huge
  10.  
  11.     for _, Player in pairs(Players:GetPlayers()) do
  12.         if Player ~= LocalPlayer and Player.Character and Player.Character:FindFirstChild("Torso") then
  13.             local Distance = (Player.Character.Torso.Position - LocalPlayer.Character.Torso.Position).magnitude
  14.  
  15.             if Distance < NearestDistance then
  16.                 NearestDistance = Distance
  17.                 NearestPlayer = Player
  18.             end
  19.         end
  20.     end
  21.  
  22.     return NearestPlayer
  23. end
  24.  
  25. function AimAt(Player)
  26.     if Player then
  27.         local Target = Player.Character.Torso.Position + Vector3.new(0, 1, 0)
  28.         local MouseVector = (Target - workspace.CurrentCamera.CFrame.p).unit
  29.         local MouseLook = CFrame.new(Mouse.Hit.p, Mouse.Hit.p + MouseVector)
  30.  
  31.         workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame:lerp(MouseLook, 0.1)
  32.     end
  33. end
  34.  
  35. function examP()
  36.     local NearestPlayer = GetNearestPlayer()
  37.     AimAt(NearestPlayer)
  38. end
  39.  
  40. game:GetService("RunService").RenderStepped:Connect(examP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement