Pathfinding service not finding a good path

I am not sure why this is happening, but ROBLOX’s pathfinding services keeps making paths that collide with walls / parts:

CODE:

function functions.WalkToChair(NPC)
	local foundChair = FindChair()
	
	if not foundChair then 
		NPC:Destroy()
		return 
	end

	local customerPath = PathfindingService:CreatePath({
		AgentRadius = 5,
		AgentHeight = 5,
		AgentCanJump = false,
		AgentCanClimb = false,
		WaypointSpacing = 2;
		Costs = generalData.CustomerCosts
	})
	
	local success, errorMessage = pcall(function()
		customerPath:ComputeAsync(NPC.PrimaryPart.Position, foundChair.Position)
	end)
	
	if success and customerPath.Status == Enum.PathStatus.Success then
		for waypointCount, waypoint in customerPath:GetWaypoints() do	
			if waypointCount >= (#customerPath:GetWaypoints() - 1) then
				foundChair:Sit(NPC.Humanoid)
				break
			end
			NPC.Humanoid:MoveTo(waypoint.Position)
			NPC.Humanoid.MoveToFinished:Wait()
		end
	else
		print(`Path unable to be computed, error: {errorMessage}`)
	end
end
1 Like

you can use SimplePath - Pathfinding Module

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.