ShoccessX

Autowalk

Sep 8th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 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 moveDirection = 1 -- 1 for forward, -1 for backward
  9. local moveInterval = 0.32 -- Interval in seconds before switching direction
  10. local lastSwitchTime = 0
  11. local isMoving = false
  12. local movementDuration = 1.6 -- Total duration for moving back and forth (adjustable)
  13. local waitDuration = 60 -- Wait time in seconds before each movement cycle
  14.  
  15. -- Function to move the character forward and backward
  16. local function moveBackAndForth(deltaTime)
  17. if isMoving then
  18. -- Move forward or backward
  19. local direction = Vector3.new(0, 0, moveDirection * 0.16).Unit -- Reduce movement speed
  20. humanoid:Move(direction, true)
  21.  
  22. -- Switch direction after the interval
  23. if tick() - lastSwitchTime >= moveInterval then
  24. moveDirection = -moveDirection
  25. lastSwitchTime = tick()
  26. end
  27. else
  28. humanoid:Move(Vector3.new(0, 0, 0), true) -- Stop movement when not moving
  29. end
  30. end
  31.  
  32. -- Main function to manage the movement cycle
  33. local function startMovementCycle()
  34. while true do
  35. wait(waitDuration) -- Wait for 60 seconds before starting the movement
  36.  
  37. -- Start moving back and forth
  38. isMoving = true
  39. local moveStartTime = tick()
  40.  
  41. -- Connect the movement function to RenderStepped to start moving
  42. local connection = runService.RenderStepped:Connect(moveBackAndForth)
  43.  
  44. -- Wait for the duration of the movement
  45. wait(movementDuration)
  46.  
  47. -- Stop moving back and forth
  48. isMoving = false
  49. connection:Disconnect() -- Disconnect the RenderStepped connection
  50.  
  51. -- Stop character movement
  52. humanoid:Move(Vector3.new(0, 0, 0), true)
  53.  
  54. -- Wait another 60 seconds before repeating the cycle
  55. end
  56. end
  57.  
  58. -- Start the movement cycle
  59. startMovementCycle()
Advertisement
Add Comment
Please, Sign In to add comment