MoveTo finishing early even without the 8 second TimeOut

Hi, I asked before on how to make it so humanoid:MoveTo’s don’t finish early in the 8 second cooldown thing. and this is what i have currently. This is for a tower defense game and the mob waypoints value is to determine which enemy is first in line. The problem is, for some reason, enemies begin moving to another waypoint a tiny bit too early, which can throw off enemy targeting. As you can see below, this is where enemies stop heading towards the waypoint and start going to the next one. Is there any way to counteract this? As always, any help I can get on this would be much appreciated.

WaypointProblem

function mob.Move(mob, map)
	local targetreached = true
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints
	
	for waypoint=1, #waypoints:GetChildren() do
		mob.MovingTo.Value = waypoint
		repeat
			humanoid:MoveTo(waypoints[waypoint].Position)
			local reached = humanoid.MoveToFinished:Wait()
		until reached
	end
	
	mob:Destroy()
	
	map.Base.Humanoid:TakeDamage(humanoid.Health)
end
3 Likes

You could try slightly moving each waypoint so that while the enemy technically still hasn’t reached the waypoint, they reach the exact position you want them to be at.

Another way would be for the enemy to move just a bit more forward once they “reached” a waypoint.

I’m not sure if these solutions would be best for long-term compatibility though, as Roblox might change the behavior of :MoveTo() if this behavior is unintentional. They should otherwise work though, but I’m not entirely sure.

Not sure how moving waypoints would fix the issue, because you’re just moving where they’re supposed to go, not where they end up deciding to go to the next waypoint.

Second solution is also a bit iffy because i dont know a good way to move enemies onto the waypoint without it looking like they’re teleporting.

I’m stuck in a dilemma about this because this can really effect gameplay and I think it’s just really incredibly stupid that MoveTo’s are so bugged.

1 Like

If you want to extend the timeout, so that they reach the MoveToFinished, then just keep calling another MoveTo before that, as the API suggests:

1 Like

Thing is, the timeout is already extended. The repeat function waits until the moveto has reached its destination. Problem is, roblox thinks that the moveto is finished just before it actually reaches right on top of the waypoint. What I guess i’m really trying to ask here is how to make sure the moveto finishes right on top of the waypoint instead of just before.

Either that or is there any other way i can move the enemy without using moveto yet having moveto-like qualities?

2 Likes

I’ve always experienced some sort of issue when using MoveToFinished:Wait() in the past. My suggestion is to use a bit of math to determine if the A.I has reached its target point as such.

function mob.Move(mob, map)
	local targetreached = true
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints
	local maxtimewithoutmove = 4; -- Attempts to move every 4 seconds.
	local timewithoutmove = maxtimewithoutmove -- Set to max time for the first pass.
    local minimumwpdistance = 1 -- Minimum waypoint distance for the mob.
	
	for waypoint=1, #waypoints:GetChildren() do
		mob.MovingTo.Value = waypoint
		while wait(0.1) do		
			if timewithoutmove >= maxtimewithoutmove) then
				timewithoutmove = 0 -- Reset and move the A.I
				humanoid:MoveTo(waypoints[waypoint].Position)
			elseif ((waypoints[waypoint].Position - mob.HumanoidRootPart.Position).Magnitude <= minimumwpdistance)
				break -- Finished moving, break out of the while loop.
			else
				timewithoutmove = timewithoutmove + 0.1; -- Since the loop waits 0.1 seconds, increase by that amount.
			end
		end
	end
	
	mob:Destroy()
	
	map.Base.Humanoid:TakeDamage(humanoid.Health)
end

I have always used MoveTo and MoveToFinished, but I have read of people using PivotTo, i just don’t have any experience with it (and it might be for parts, not humanoids, not sure).

I’ve wrote the answer on Gnome Code’z tower defenze tutorial but here you go:
Ive written a function which replacez moveTo!
Basically, the 8 seconds iz there becauze the character may never find the location it goez to, MoveToFinizhed:Connect(function(successful) successful will be true if it makes and and false if it doesnt make it in time!

code:

local function MoveToFinished(humanoid,position)
	local Timeout = true
	local event = humanoid.MoveToFinished:Connect(function(successful) if not successful then humanoid:MoveTo(position) return end if successful then Timeout=false end end)
	repeat task.wait(.2) until Timeout==false
	event:Disconnect()
	return
end

all you have to do with it is replace
Humanoid.MoveToFinished:Wait()
with MoveToFinished(TheHumanoidHere,PositionItShouldGoTo)

zimple az that :happy1: your welcome!
@RoxSerpent 99.99% guarantee thiz work

replace with thiz:

local function MoveToFinished(humanoid,position)
	local Timeout = true
	local event = humanoid.MoveToFinished:Connect(function(successful) if not successful then humanoid:MoveTo(position) return end if successful then Timeout=false end end)
	repeat task.wait(.2) until Timeout==false
	event:Disconnect()
	return
end
function mob.Move(mob, map)
	local targetreached = true
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints
	
	for waypoint=1, #waypoints:GetChildren() do
		mob.MovingTo.Value = waypoint
		MoveToFinished(humanoid,waypoints[waypoint].Position)
	end
	
	mob:Destroy()
	
	map.Base.Humanoid:TakeDamage(humanoid.Health)
end
4 Likes

Try using MoveToFinished. It will only fire once it is finished moving your mob to its desired location.

Absolute chad working.

The only thing to work this out is to change the

mob.MovingTo.Value = waypoint

to:

Model.Humanoid:MoveTo(EnemyPoint[waypoint].Position)

It’s working for me and i tested it out.

1 Like