ShoccessX

mover

Sep 9th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. -- LocalScript placed in StarterPlayerScripts or StarterCharacterScripts
  2.  
  3. local player = game.Players.LocalPlayer
  4. local character = player.Character or player.CharacterAdded:Wait()
  5. local humanoid = character:WaitForChild("Humanoid")
  6. local runService = game:GetService("RunService")
  7.  
  8. local moveSpeed = 0.90 -- Movement speed; adjust as needed
  9. local moveDirection = Vector3.new(0, 0, 1) -- Move forward direction
  10.  
  11. -- Define the target coordinates
  12. local targetPosition = Vector3.new(-49.097503662109375, 3.5023391246795654, -407.1893310546875)
  13. local tolerance = 1 -- Distance tolerance to consider as "reached"
  14.  
  15. -- Movement connection variable
  16. local movementConnection
  17.  
  18. -- Function to move the character forward continuously
  19. local function moveForward()
  20. -- Check if the character has reached or is close to the target position
  21. if (character.PrimaryPart.Position - targetPosition).magnitude > tolerance then
  22. -- Apply movement in the forward direction
  23. humanoid:Move(moveDirection * moveSpeed, true)
  24. else
  25. -- Stop the movement
  26. if movementConnection then
  27. movementConnection:Disconnect()
  28. movementConnection = nil
  29. end
  30. end
  31. end
  32.  
  33. -- Main function to manage continuous movement
  34. local function startMovement()
  35. -- Connect the movement function to RenderStepped to move continuously
  36. movementConnection = runService.RenderStepped:Connect(moveForward)
  37. end
  38.  
  39. -- Start the continuous movement
  40. startMovement()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment