Problem With Pathfinding Service

Hello, I want to make a feature in my game where I have NPC’s walking around my map.


I am pretty sure my code is fine, however when I run the code The cumputed path’s status comes up as “Enum.PathStatus.NoPath”.

I checked the pathmesh for my game and it turns out that there is no purple mesh over my game. is there anyway to fix this? I also checked another game of mine and I could see the mesh for that one just fine.

I’m no expert with the PathfindingService, thus I’ll refer you over to this that I found online: Pathfinding script's path object returning Enum.PathStatus.NoPath

Hope it helps!

Alright Thanks, ill give it a try.

Just an update, the link did not cover my specific problem but thank you for the referral.

Here’s a script that I use for my npc:

local NPC = script.Parent -- set to the directory of your npc

local PathFindingService = game:GetService('PathfindingService')

local pathParams = {
	["AgentHeight"] = 15, -- height of your npc
	["AgentRadius"] = 4, -- radius of your npc
	["AgentCanJump"] = false -- whether it can jump or not
}

local Path = PathFindingService:CreatePath(pathParams)

local function GetDestination()
	local Waypoints = game.Workspace.Waypoints-- change to where your positions are
	local ChosenWaypoint = Waypoints:GetChildren()[math.random(1,#Waypoints:GetChildren())]
	
	return ChosenWaypoint
end

local function Patrol()
	local Destination = GetDestination()
	
	if Destination then
		Path:ComputeAsync(NPC.HumanoidRootPart.Position,Destination.Position)
		local Waypoints = Path:GetWaypoints()
		
		if Path.Status == Enum.PathStatus.Success then
			for Index, Waypoint in pairs(Waypoints) do
				if Waypoint.Action == Enum.PathWaypointAction.Jump then
					NPC.Humanoid.Jump = true
				end
				NPC.Humanoid:MoveTo(Waypoint.Position)
				NPC.Humanoid.MoveToFinished:Wait()
			end
		else
			warn('Unable to make a path')
		end

	else
		warn('No Destination')
	end
end

while wait(0.25) do
	Patrol()
end

Thank you for the advice, however from what I am experiencing, I believe there is a problem with my map as to where path finding service does register anywhere on my map as path, and that is why my script does not work. If possible I would like to figure out the cause of that problem. I will definitely learn and take from your script however. :smiley:

Got a notification for the link, glad I could help :smiley:

The problem in the link is the same as this one. Your path’s goal might be too high, or there might be a large, transparent “hitbox” part in the area.

1 Like

As it turns out, after checking my game again, There was a humanoid Parented to the workspace which was messing with the pathfinding, Thank you everyone for the advice andsupport :slight_smile:

No problem, good luck with your project :smiley: