Pathfinding Chase script

Warning: This can be a somewhat complex script

How do you make a pathfinder create a path, move to one step in the path, then recalculate another path, then move to the next step in that path. I need to know so that this is always computing different paths just in case the path is always changing (the character moves, the path is blocked by a closing door, etc.)

Humanoid.MoveToFinished:Connect(function()
Poop()	
end)

function Poop()
	local CharPos = Root.Position	
	local Target = script.Value.Value.Position
	local Path = PathwayService:FindPathAsync(CharPos,Target)	
	local Woop = Path:GetWaypoints()
	Humanoid:MoveTo(Woop[2].Position)
	Humanoid.MoveToFinished:Wait(2)
end

	
Poop()

It kinda works, sometimes it doesn’t. However, when it does it is not smooth. How do I get it to direct to one waypoint, then as soon as it reaches another waypoint, it already moves to the next from an entirely different path (or maybe have the current one altered with new waypoints).

Should I have the already used waypoints become deleted?

1 Like