NPC Path not Computing at all when a path is Created

The issue is when I have it print Path.Status it says Enum.PathStatus.NoPath
I have a warning in there warn('NPC Path Failed! No path available. trying to reach: ' .. tostring(Goal.Name)) which is coming in the console, so above that I have printed Path.Status which once again is Enum.PathStatus.NoPath when there is clearly a path.

local function MainNPCFollowing(Character, Goal)
	print('Main NPC function called.')
	local Waypoints = {}
	local Path = PathfindingService:CreatePath()
	local WaypointIndex = 1
	local Humanoid = Character:WaitForChild('Humanoid')
	local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
	
	print('Passed variables')
	
	for index, item in pairs(Character:GetChildren()) do
		if item:IsA("BasePart") then
			item:SetNetworkOwner(nil)
		end
	end 
	
	print('passed opti')
	
	local function FollowPath()
		Path:ComputeAsync(HumanoidRootPart.Position, Goal.Position)
		Waypoints = {}
		
		print('PS: ' .. tostring(Path.Status))
		if Path.Status == Enum.PathStatus.Success then
			Waypoints = Path:GetWaypoints()
			WaypointIndex = 1
			Humanoid:MoveTo(Waypoints[WaypointIndex].Position)
		else
			warn('NPC Path Failed! No path available. trying to reach: ' .. tostring(Goal.Name))
			Goal.Transparency = 0
			Goal.Color = Color3.fromRGB(255, 0, 4)
			Goal.Material = Enum.Material.Neon
		end
	end
	
	print('passed follow')
	
	-- Fires when the humanoid finishes moving to it's path (according to the script)
	Humanoid.MoveToFinished:Connect(function(Reached)
		if Reached and WaypointIndex < #Waypoints then
			WaypointIndex += 1
			if Waypoints[WaypointIndex].Action == Enum.PathWaypointAction.Jump then
				Humanoid.Jump = true
			end
			Humanoid:MoveTo(Waypoints[WaypointIndex].Position)
		end
	end)
	
	-- Fires when the path is blocked
	Path.Blocked:Connect(function(BlockedWaypointIndex)
		warn('Path blocked.')
		if BlockedWaypointIndex > WaypointIndex then
			FollowPath(Goal)
		end
	end)
	
	FollowPath(Goal)
end

Any help is appreciated. Thanks
ASAP as this is a core feature in my game.
Note: I have more code above and below but this is the main function

Try lowering the AgentRadius parameter in the configs you can pass to the new path object.

Also toggle the Studio setting called like NavMesh Visualization or something (at the bottom of the main Studio settings screen) and see if there’s any obstructions on that specific path.

You can use parts to modify the NavMesh, making certain paths recompute so the area is traversable. Use collision groups so those parts don’t collide with anything at all, their only purpose is to force the NavMesh to regenerate.

Hope it helps

I fixed the main issue, but now I am experiencing the NPCs occasionally running into walls.
image

This is probably because your agent radius is too low, or your walls are too thin.

1 Like