My Pathfinding Script Won't Work!

I was watching this tutorial online on how to use Pathfinding Service but for some reason it’s not working…

local PFS = game:GetService("PathfindingService")

local Humanoid = script.Parent.Humanoid

local RootPart = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")

local Destination = workspace.Part.Position

local Path = PFS:CreatePath()
Path:ComputeAsync(RootPart.Position, Destination)

local Waypoints = Path:GetWaypoints()

for key,waypoint in pairs(Waypoints) do
	Humanoid:MoveTo(waypoint.Position)
	
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	
	Humanoid.MoveToFinished:Wait()
end

The Tutorial Is Here!

1 Like

Are you getting any errors? If so, please share them with us, so we can better understand how to provide support.

1 Like

Maybe try first a simpler code just with the move function and see if it works? We can’t do so much without any error log.

The code is a LocalScript or a Script? If it is a LocalScript and the humanoid is an NPC, use a Script. Also check if the Destination and RootPart are correct.

I tried your script and it worked perfectly, just make sure ton unanchored your NPC’s humanoidRootPart and it should works.

3 Likes