Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- LocalScript placed in StarterPlayerScripts or StarterCharacterScripts
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local runService = game:GetService("RunService")
- local moveSpeed = 0.90 -- Movement speed; adjust as needed
- local moveDirection = Vector3.new(0, 0, 1) -- Move forward direction
- -- Define the target coordinates
- local targetPosition = Vector3.new(-49.097503662109375, 3.5023391246795654, -407.1893310546875)
- local tolerance = 1 -- Distance tolerance to consider as "reached"
- -- Movement connection variable
- local movementConnection
- -- Function to move the character forward continuously
- local function moveForward()
- -- Check if the character has reached or is close to the target position
- if (character.PrimaryPart.Position - targetPosition).magnitude > tolerance then
- -- Apply movement in the forward direction
- humanoid:Move(moveDirection * moveSpeed, true)
- else
- -- Stop the movement
- if movementConnection then
- movementConnection:Disconnect()
- movementConnection = nil
- end
- end
- end
- -- Main function to manage continuous movement
- local function startMovement()
- -- Connect the movement function to RenderStepped to move continuously
- movementConnection = runService.RenderStepped:Connect(moveForward)
- end
- -- Start the continuous movement
- startMovement()
Advertisement
Add Comment
Please, Sign In to add comment