Advertisement
AnonymousJG179

Locker Missile PVP

May 27th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. -- Locks the player's mouse and point of view onto the nearest player from a different team
  2. -- Toggle on/off with the equals (=) key
  3.  
  4. local UserInputService = game:GetService("UserInputService")
  5. local Players = game:GetService("Players")
  6. local player = Players.LocalPlayer
  7. local camera = game.Workspace.CurrentCamera
  8. local isEnabled = false
  9.  
  10. -- Function to find the nearest player from a different team
  11. local function findNearestEnemyPlayer()
  12. local nearestPlayer = nil
  13. local minDistance = math.huge
  14. local playerPosition = player.Character.HumanoidRootPart.Position
  15. local playerTeam = player.Team
  16.  
  17. for _, otherPlayer in pairs(Players:GetPlayers()) do
  18. if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") and otherPlayer.Team ~= playerTeam then
  19. local distance = (otherPlayer.Character.HumanoidRootPart.Position - playerPosition).Magnitude
  20. if distance < minDistance then
  21. minDistance = distance
  22. nearestPlayer = otherPlayer
  23. end
  24. end
  25. end
  26.  
  27. return nearestPlayer
  28. end
  29.  
  30. -- Function to handle key press
  31. local function onKeyPress(input)
  32. if input.KeyCode == Enum.KeyCode.Equals then
  33. isEnabled = not isEnabled
  34. end
  35. end
  36.  
  37. -- Connect the key press function to the UserInputService
  38. UserInputService.InputBegan:Connect(onKeyPress)
  39.  
  40. -- Main loop to update camera position
  41. game:GetService("RunService").RenderStepped:Connect(function()
  42. if isEnabled then
  43. local nearestPlayer = findNearestEnemyPlayer()
  44. if nearestPlayer and nearestPlayer.Character and nearestPlayer.Character:FindFirstChild("HumanoidRootPart") then
  45. local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position
  46. camera.CFrame = CFrame.new(camera.CFrame.p, targetPosition)
  47. end
  48. end
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement