MoveToFinished Firing too early even without the 8 second timeout

I’ve been stumped on this issue with my waypoint movement system that has been recently been bugging out. Right now, I have it so the moveto does not timeout and also does not end until the MoveToFinished event fires. The problem with it however is that for some reason MoveToFinished still fires too early. To counteract this i have a Move() function that moves the mob the rest of the way to the waypoint. This causes issues when the server is experiencing lag or the mob changes speed that can cause it to “overshoot” the waypoint. How do I get rid of the early stop without a wait function?

	for waypoint = headingto, #waypoints:GetChildren() do
		if mob:FindFirstChild("MovingTo") then
			mob.MovingTo.Value = waypoint

			repeat
				humanoid:MoveTo(waypoints[waypoint].Position)
				local reached = humanoid.MoveToFinished:Wait()
			until reached -- supposed to stop at waypoint but is just a bit short
			if mob:FindFirstChild("HumanoidRootPart") then
				humanoid:Move((waypoints[waypoint].Position - (mob.HumanoidRootPart.Position - offset)).Unit)
				local humanoidwalkspeed = mob.Humanoid.WalkSpeed
				wait((waypoints[waypoint].Position - (mob.PrimaryPart.Position - offset)).Magnitude/mob.Humanoid.WalkSpeed) --moved the rest of the distance
			end
		end
	end

image

image

1 Like

I tried your code snippet, and it seems to work for me.

local model = script.Parent
	local waypoints = model.Waypoints
	local mob = model.Mob
		local humanoid = mob.Humanoid

function startWaypointing()
	local headingto = 1
	
	for waypoint = headingto, #waypoints:GetChildren() do
		if mob:FindFirstChild("MovingTo") then
			mob.MovingTo.Value = waypoint

			repeat
				humanoid:MoveTo(waypoints[waypoint].Position)
				local reached = humanoid.MoveToFinished:Wait()
			until reached -- supposed to stop at waypoint but is just a bit short
			
			--[[ the mob didn't fall short of the waypoints so I commented this out
			
			if mob:FindFirstChild("HumanoidRootPart") then
				humanoid:Move((waypoints[waypoint].Position - (mob.HumanoidRootPart.Position - offset)).Unit)
				local humanoidwalkspeed = mob.Humanoid.WalkSpeed
				wait(
					(waypoints[waypoint].Position - (mob.PrimaryPart.Position - offset)).Magnitude
						/ mob.Humanoid.WalkSpeed
				) --moved the rest of the distance
			end
			]]
		end
	end
end

wait(5)
startWaypointing()

Here’s the result
https://gyazo.com/c4af0f9246011de09dc692deaa5918ec

and this is the setup I used

Screenshot 2022-11-20 at 00.42.35


Are there any obstructions around the waypoints that could block the mob’s path, and is there anything else which makes the mob move? I’m not sure if latency might have anything to do with it.

There isn’t any obstructions in the maps in the game. The mobs are collision grouped to avoid anything that isn’t the path anyway. I set up an example and took video to show what i am looking for.
In the first video is without the wait and with only the movetofinished().

You can see the mob starts to move to the next waypoint before it reaches the center of the waypoint. It is a minor discrepancy but it really annoys me.

In the second video it has the wait() function at the end, and you can see the mob moves to the center of the waypoint before moving to the next one.

You could try a solution like the one outlined in this post,

I don’t recommend this, try to go for an event approach. And also, make sure you are setting the network owner of your npc humanoidrootparts to nil, so that the server owns that and that there is no lag/sttutter.

Humanoid.MoveToFinished:Connect(function(reached)
    moveToNextPoint(nextWaypoint)
end)