How can I fix my zombie's movement in a tower defense game im making?

  1. What do you want to achieve?
    I want to fix the way my zombies walk in a tower defense gaming im trying to make

  2. What is the issue?
    My zombies randomly skip the path and go straight to the exit. (picture because i cant upload videos)


    The line is showing where they’re skipping the path. They stop for like 1 second the skip it.

  3. What solutions have you tried so far?
    I’ve tried seeing if the timing was wrong on the pathfinding or the block they go to was in the wrong spot but it wasn’t. Here’s the script if you need it.

local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local nodes = game.Workspace.Path1:GetChildren()
table.sort(nodes, function(nodeA, nodeB)
	local nodeNumberA = string.match(nodeA.Name, "%d+")
	local nodeNumberB = string.match(nodeB.Name, "%d+")
	return tonumber(nodeNumberA) < tonumber(nodeNumberB)
end)

for _, node in ipairs(nodes) do
	hum:MoveTo(node.Position)
	local distance = (torso.Position - node.Position).Magnitude
	wait (distance / hum.WalkSpeed)
end

That is an error with my faster zombies. The normal zombies stop even earlier in the path and skip it and I don’t know why.

Can you screenshot what it says on Console?

I always get those errors so i’m not sure what the problem is.

If you always get those then its a silent error, the syntax etc is fine but it doesnt work, when I am on pc, I will look into it.

Alright. Hopefully in the mean time someone finds an answer.

well what are the nodes locations? make them visible then screenshot the map

They’re not centered right on the path because they only walk to the side of it and not directly in the middle.

The problem is that when using MoveTo with an NPCS humanoid, it stops after 8 seconds to prevent it from getting stuck.

Hello so i’ve been a dev for 5 years and i experienced this. i had to change my code to this:
local zombie = script.Parent
local waypoints = workspace.Waypoints

for waypoint=1, #waypoints:GetChildren() do
zombie.Humanoid:MoveTo(waypoints[waypoint].Position)
zombie.Humanoid.MoveToFinished:Wait()
end

bro really necroposted to say hes experienced