NPC moveTo() keep stopping

When my npc’s are leaving the building sometimes they get stuck at the doorway. Their path is not blocked but they just stop moving when trying to get to the next waypoint. They also have no trouble walking into the building just sometime when walking out.

Here is my pathfinding code, basically copied from this tutorial Character Pathfinding

local function pathFind(id: string, model: Model, humanoid: Humanoid, start: Vector3, finish: Vector3)	
	local path = PathFindingService:CreatePath({
		AgentRadius = 3
	})
	local waypoints = {}
	local nextWaypointIndex: number = nil
	local blockedWaypointIndex: number = nil
	local reachedConnection
	local blockedConnection

	
	local function followPath()		
		local success, errorMessage = pcall(function()
			path:ComputeAsync(start, finish)
		end)
		
		if success and path.Status == Enum.PathStatus.Success then
			waypoints = path:GetWaypoints()

			blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
				print("Path blocked")
				if blockedWaypointIndex >= nextWaypointIndex then
					blockedConnection:Disconnect()
					followPath()
				end
			end)
			
			if not reachedConnection then
				reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
					print("move")
					if reached and nextWaypointIndex < #waypoints then
						print("Move to wayout")
						nextWaypointIndex += 1
						humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
					else
						print("Final waypoint reached")
						reachedConnection:Disconnect()
						blockedConnection:Disconnect()
						model:Destroy()
						NPCList = Stream.new(NPCList):filter(function(x: t.NpcType) return x.id ~= id end):collect()
					end
				end)
			end

			nextWaypointIndex = 2
			humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
		else
			warn("Path not computed!", errorMessage)
		end
	end
	followPath()
end

What did you change? Might help pinpoint any issues.

What do you mean by change? This has always been happening

Here is my pathfinding code, basically copied from this tutorial Character Pathfinding

Oh, well it is the same apart from what happens when the last waypoint is reached

When something interferes with :MoveTo, in this case the door, the function gets cancelled.

1 Like

The doors are no collide and it happens even if they are removed. Is there a way to tell if moveto get cancelled?

It is clear tat the npc got stuck on an invisible object which made the :MoveTo cancel.

If you are using replicated tweening it could have gotten stuck on the opening door.


No door, no invisible parts, yet they still get stuck :thinking:

Weird. Maybe turn of their collisions and basically make them noclip?

1 Like

If you go to ’ Ignoring Obstacles’ in this article, you can collide through the door without an issue, if that’s what you want.


I switched to server view and a lot of the npcs are walking into walls so I guess that explains why there appear to be getting stuck from the clients view point. Now i just need to figure out why they walk into walls


Mystery solved, some of the npcs, HumanoidRootParts seems to be getting detached from the npc