Advertisement
AnonymousJG179

Locker Missile PVP 2.0

Jul 8th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. -- Toggle Lock-on and Enemy Player Movement Prediction Script for Roblox
  2.  
  3. local UserInputService = game:GetService("UserInputService")
  4. local Players = game:GetService("Players")
  5. local player = Players.LocalPlayer
  6. local camera = game.Workspace.CurrentCamera
  7. local lockedEnemy = nil
  8. local isLockedOn = false
  9. local isPredictingMovement = false
  10.  
  11. -- Function to find the nearest enemy player
  12. local function findNearestEnemy()
  13. local nearestEnemy = nil
  14. local minDistance = math.huge
  15. local playerPosition = camera.CFrame.Position
  16.  
  17. for _, otherPlayer in pairs(Players:GetPlayers()) do
  18. if otherPlayer ~= player and otherPlayer.TeamColor ~= player.TeamColor and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  19. local distance = (otherPlayer.Character.HumanoidRootPart.Position - playerPosition).Magnitude
  20. if distance < minDistance then
  21. minDistance = distance
  22. nearestEnemy = otherPlayer
  23. end
  24. end
  25. end
  26.  
  27. return nearestEnemy
  28. end
  29.  
  30. -- Function to update camera position towards target enemy player
  31. local function updateCameraPosition(target)
  32. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  33. local targetPosition = target.Character.HumanoidRootPart.Position
  34. camera.CFrame = CFrame.new(camera.CFrame.p, targetPosition)
  35. end
  36. end
  37.  
  38. -- Function to predict enemy player movement
  39. local function predictEnemyMovement(target)
  40. if target and target.Character and target.Character:FindFirstChild("Humanoid") then
  41. local humanoid = target.Character.Humanoid
  42. local currentPosition = target.Character.HumanoidRootPart.Position
  43. local currentVelocity = humanoid.RootPart.Velocity
  44.  
  45. -- Predict future position based on current position and velocity
  46. local predictionTime = 1.0 -- Adjust prediction time as needed
  47. local predictedPosition = currentPosition + currentVelocity * predictionTime
  48.  
  49. camera.CFrame = CFrame.new(camera.CFrame.p, predictedPosition)
  50. end
  51. end
  52.  
  53. -- Function to handle key press
  54. local function onKeyPress(input)
  55. if input.KeyCode == Enum.KeyCode.Equals then
  56. isLockedOn = not isLockedOn
  57. if isLockedOn then
  58. lockedEnemy = findNearestEnemy()
  59. end
  60. elseif input.KeyCode == Enum.KeyCode.Z then
  61. isPredictingMovement = not isPredictingMovement
  62. end
  63. end
  64.  
  65. -- Connect the key press function to the UserInputService
  66. UserInputService.InputBegan:Connect(onKeyPress)
  67.  
  68. -- Main loop to update camera position
  69. game:GetService("RunService").RenderStepped:Connect(function()
  70. if isLockedOn and lockedEnemy and lockedEnemy.Character and lockedEnemy.Character:FindFirstChild("HumanoidRootPart") then
  71. if isPredictingMovement then
  72. predictEnemyMovement(lockedEnemy)
  73. else
  74. updateCameraPosition(lockedEnemy)
  75. end
  76. end
  77. end)
  78.  
  79. -- Check if the locked enemy player or the player who executed the script dies
  80. player.Character.Humanoid.Died:Connect(function()
  81. lockedEnemy = nil
  82. isLockedOn = false
  83. end)
  84.  
  85. Players.PlayerRemoving:Connect(function(removedPlayer)
  86. if lockedEnemy == removedPlayer then
  87. lockedEnemy = nil
  88. isLockedOn = false
  89. end
  90. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement