Advertisement
adnsko

Script For Arsenal

May 30th, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | Gaming | 0 0
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local RunService = game:GetService("RunService")
  4.  
  5. local localPlayer = Players.LocalPlayer
  6. local mouse = localPlayer:GetMouse()
  7. local camera = workspace.CurrentCamera
  8. local target = nil
  9.  
  10. local function findNearestEnemy()
  11. local nearestDistance = math.huge
  12. local nearestEnemy = nil
  13.  
  14. for _, player in ipairs(Players:GetPlayers()) do
  15. if player ~= localPlayer and player.Team ~= localPlayer.Team then
  16. local character = player.Character
  17. if character and character:FindFirstChild("HumanoidRootPart") then
  18. local distance = (character.HumanoidRootPart.Position - localPlayer.Character.HumanoidRootPart.Position).magnitude
  19. if distance < nearestDistance then
  20. nearestDistance = distance
  21. nearestEnemy = player
  22. end
  23. end
  24. end
  25. end
  26.  
  27. return nearestEnemy
  28. end
  29.  
  30. local function lockOntoTarget(targetPlayer)
  31. if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") then
  32. local targetHRP = targetPlayer.Character.HumanoidRootPart
  33. localPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(localPlayer.Character.HumanoidRootPart.Position, targetHRP.Position)
  34.  
  35. local function updateCamera()
  36. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  37. local targetPosition = targetHRP.Position
  38. camera.CFrame =
  39. CFrame.new(camera.CFrame.Position, targetPosition)
  40. else
  41. RunService:UnbindFromRenderStep("LockOnUpdate")
  42. end
  43. end
  44.  
  45. RunService:BindToRenderStep("LockOnUpdate", Enum.RenderPriority.Camera.Value + 1, updateCamera)
  46. end
  47. end
  48.  
  49. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  50. if input.UserInputType == Enum.UserInputType.MouseButton1 and not gameProcessed then
  51. target = findNearestEnemy()
  52. lockOntoTarget(target)
  53. end
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement