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