Why isn't this pathfinding script working?

Hello devs,

I have a problem with this script, and I’m not sure why it’s not working.
(I’m really new to pathfinding)

local pathService = game:GetService("PathfindingService")

local path
local waypoints

game.Players.PlayerAdded:Wait()
game.Players:GetPlayers()[1].CharacterAdded:Wait()

path = pathService:CreatePath()
path:ComputeAsync(script.Parent.UpperTorso.Position, game.Players:GetPlayers()[1].Character.UpperTorso.Position)
waypoints = path:GetWaypoints()
for _, i in pairs(waypoints) do
	script.Parent.Humanoid:MoveTo(i.Position)
	script.Parent.Humanoid.MoveToFinished:Wait()
end

EDIT: Please refer to this site for getting waypoints:

https://developer.roblox.com/en-us/api-reference/function/Path/GetWaypoints

I did that, as you can see in the script.

I think this line might be causing issues.

I’ve updated the script a bit and I get a pathblocked x2 at the start and a few others every now and then, so I think it’s something to do with the moveto

local pathService = game:GetService("PathfindingService")

local path
local waypoints

game.Players.PlayerAdded:Wait()
game.Players:GetPlayers()[1].CharacterAdded:Wait()

local walkAnim = script.Parent.Humanoid:LoadAnimation(script.Parent.Walk)
local jumpAnim = script.Parent.Humanoid:LoadAnimation(script.Parent.Jump)

path = pathService:CreatePath()
path:ComputeAsync(script.Parent.HumanoidRootPart.Position, game.Players.BriefYayyayyay.Character.HumanoidRootPart.Position)
waypoints = path:GetWaypoints()
for _, i in pairs(waypoints) do
	if path.Blocked then
		print("Path Blocked")
	end
	if i.Action == Enum.PathWaypointAction.Walk then
		script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Running)
		walkAnim:Play()
	elseif i.Action == Enum.PathWaypointAction.Jump then
		script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		jumpAnim:Play()
	end
	script.Parent.Humanoid:MoveTo(i.Position)
	script.Parent.Humanoid.MoveToFinished:Wait()
end

See my solution to this topic here:

Ok so it turns out that the HumanoidRootPart can’t be anchored to use pathfinding service…

1 Like