Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a reason MoveTo Stops after a couple seconds?

So the function move to I tried to move my character to a really far direction on the x axis and there were no obstacles and there was solid ground so the character could walk on it. But after 4 seconds The whole move to function stopped moving and I tried again just in case I thought I moved my character and I tried this for 3 times and i Kept on stopping is there a script or way to get around this?

game.players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.Humanoid:MoveTo(Part.Position) -- Stops in 4 seconds

1 comment

0

Humanoid:MoveTo includes a timout of 8 seconds see https://developer.roblox.com/api-reference/function/Humanoid/MoveTo for more info.

1 answer

So, as kingdom5 said in the comments, yes there is a timeout of 8 seconds, so how can we get around this? We know that every 8 seconds that the WalkToPoint is not reached, the Function will time out. However, this also triggers another signal: Humanoid.MoveToFinished()

We can make the Humanoid:MoveTo() continue being played until the player reaches the goal (assuming they are unable to move freely)

What if we reach the part before the timer runs out? Well, we want to make sure we're close enough to the part for it to set off the MoveToFinished without setting it off too early, so we can use .magnitude to determine the distance from the part for this.

Server Script

local Part = workspace:WaitForChild("Part")
local stopper = false

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local human = char:WaitForChild("Humanoid")
		local root = char:WaitForChild("HumanoidRootPart")
		human:MoveTo(Part.Position)
		
		human.MoveToFinished:Connect(function()
			if (root.Position - Part.Position).magnitude > 5 and stopper == false then
				human:MoveTo(Part.Position)
			else
				stopper = true
			end
		end)
	end)
end)

Where the part we are trying to reach is named "Part" within the Workspace

The "stopper" is to make sure that the (essentially a) loop will not play once its goal has been reached.

This discussion is preserved as it was. New answers, comments, and votes are closed.