humanoid:MoveTo() stopping short of the position it is supposed to move to

but it pauses when it reaches the waypoint because of the loop

the script helps on the long sections however it still stops short of the waypoints(i made them smaller to see if that would help)
it pauses here for whatever reason
image

Can you try decreasing the task.wait() time in the function? Make it like 0.2 or 0.5

that would still produce delay though

1 Like

if i can run the task.wait and also break the loop if the target is reached at the same time then it would work

local function moveTo(humanoid, targetPoint, andThen)
	local targetReached = false

	-- listen for the humanoid reaching its target
	local connection
	connection = humanoid.MoveToFinished:Connect(function(reached)
		targetReached = true
		connection:Disconnect()
		connection = nil
		if andThen then
			andThen(reached)
		end
		
	end)

	-- start walking
	humanoid:MoveTo(targetPoint)

	-- execute on a new thread so as to not yield function
	task.spawn(function()
		while not targetReached do
		-- does the humanoid still exist?
		if not (humanoid and humanoid.Parent) then
			break
		end
		-- has the target changed?
		if humanoid.WalkToPoint ~= targetPoint then
			break
		end
		-- refresh the timeout
		humanoid:MoveTo(targetPoint)
		task.wait(6)
		end
	
	
	-- disconnect the connection if it is still connected
	if connection then
		connection:Disconnect()
		connection = nil
	end
	end)

	repeat wait() print(targetReached) until targetReached

	return

end

Try this

1 Like

works like a charm! however it still stops short of the waypoints

How? Can you share a video? In my test place it works fine without any delay


it still doesn’t go to the waypoint and instead just stops right before

actually i have an idea, give me a moment

Doesn’t just moving the waypoints forward work?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.