Advertisement
YouIsMe_MeIsYou

aimlock

Feb 16th, 2021 (edited)
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. local localPlayer = game:GetService("Players").LocalPlayer
  2.  
  3. local function player()
  4. local target = nil
  5. local dist = math.huge
  6.  
  7. for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  8. if v.Name ~= localPlayer.Name then
  9. if v.Character and v.Character:FindFirstChild("Head") and v.Character.Humanoid.Health > 0 and v.Character:FindFirstChild("Head") and v.TeamColor ~= localPlayer.TeamColor then
  10. local magnitude = (v.Character.HumanoidRootPart.Position - localPlayer.Character.HumanoidRootPart.Position).magnitude
  11.  
  12. if magnitude < dist then
  13. target = v
  14. dist = magnitude
  15. end
  16. end
  17. end
  18.  
  19. return target
  20. end
  21.  
  22.  
  23. local camera = game.Workspace.CurrentCamera
  24. local UIS = game:GetService("UserInputService")
  25. local aim = false
  26.  
  27. game:GetService("RunService").RenderStepped:Connect(function()
  28. if aim then
  29. camera.CFrame = CFrame.new(camera.CFrame.Position,player().Character.Head.Position)
  30. end
  31. end)
  32.  
  33. UIS.InputBegan:Connect(function(inp)
  34. if inp.UserInputType == Enum.UserInputType.MouseButton2 then
  35. aim = true
  36. end
  37. end)
  38.  
  39. UIS.InputEnded:Connect(function(inp)
  40. if inp.UserInputType == Enum.UserInputType.MouseButton2 then
  41. aim = false
  42. end
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement