Path finding npc bugging out

I want this npc to jump on blocks across an obby. It is able to do it when I test it in studio but when there are other players doing the obby at the same time the npc bugs out and becomes very slow and doesn’t jump resulting in it falling into water and dying.

local path = game:GetService("PathfindingService"):CreatePath()
	path:ComputeAsync(workspace.Larry.Head.Position, workspace.goal.Position)	
	local waypoints = path:GetWaypoints()
	
	if path.Status == Enum.PathStatus.Success then
		for _, waypoint in pairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				workspace.Larry.Humanoid.Jump = true
			end
			workspace.Larry.Humanoid:MoveTo(waypoint.Position)
			workspace.Larry.Humanoid.MoveToFinished:Wait(2)
		end
	else
		--print("Path unsuccessful")
		wait(2)
end

I have tried variations of this script but the bug is still there. Any idea what could be causing this? Thanks.

Sounds like the other players are influencing the nav mesh. Not sure if the pathfinding service acknowledges this, but have you tried adding the players and the npcs to a collision group so they can’t hit each other?

1 Like

If you’re only calculating the path once then, as @Barothoth said, the path will take into account were players were only when the path was computed which could cause undesirable behavior. Another option is to use the path.Blocked event to re-compute the path when it can’t complete it’s movement.

1 Like