Zombie Doesn't Follow Waypoints

Hey, I’m just a little stuck with pathfinding. I’m completely new to the Pathfinding service and have been playing around with it and ran into an issue; when I create a path it creates it “correctly” but the bot doesn’t follow it…

image

I’ve gone off of the script provided on the API page but I’ve seem to have broken it somehow.

local function ChaseTarget()
	local Path = PathService:CreatePath(PathParams)
	Path:ComputeAsync(ParentRoot.Position, TargetRoot.Position)
	
	local Waypoints = Path:GetWaypoints()

	for _, Point in pairs(Waypoints) do
		
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(0.6, 0.6, 0.6)
		part.Position = Point.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace
		
		ParentHuman:MoveTo(Point.Position)
		
	end
end

Any help would be appreciated.

You’re not waiting for the zombie to finish moving to the first waypoint. You should put a ParentHuman.MoveToFinished:Wait() on the line after ParentHuman:MoveTo().

Essentially what’s happening is that the zombie moves to the first waypoint, but since you’re not waiting for it to stop moving, the next iteration starts which overwrites the goal and moves to the next waypoint; where, again, you’re not waiting for it to stop moving to the next waypoint and it overwrites the goal to move to the third… all the way to the last waypoint.

2 Likes