How do I wait for the path to finish in pathfindingservice

hello I know whats wrong and I know the solution. I just dont know how to do the solution. Bassically I remember there being some sort of path:Wait() or path.completed:Wait() so that it waits for the npc to get to the final path but I forgot its name.

Heres the code:

local pathfindingService = game:GetService("PathfindingService")

local basePos = workspace.Base.Position
local starting = script.Parent:GetPivot().Position
local direction = (basePos - starting).Unit -- gets the direction vector from NPC to target
local base = game.Workspace.Base
local baseSize = base.Size

-- Calculate a new ending position that is offset from the center of the base
local endingOffset =, 0, 0)

if starting.X < base.Position.X then
	endingOffset = + 10, 0, endingOffset.Z)
if starting.X > base.Position.X then
	endingOffset = + 10), 0, endingOffset.Z)
if starting.Z < base.Position.Z then
	endingOffset =, 0, baseSize.Z/2 + 10)
if starting.Z > base.Position.Z then
	endingOffset =, 0, -(baseSize.Z/2 + 10))

local ending = base.Position + endingOffset * direction

-- Compute the path to the new ending position
local path = pathfindingService:CreatePath()


path:ComputeAsync(starting, ending)

for i, waypoint in ipairs(path:GetWaypoints()) do
	local X = math.floor(waypoint.Position.X / 5) * 5
	local Y = math.floor(waypoint.Position.Y / 5) * 5
	local Z = math.floor(waypoint.Position.Z / 5) * 5

	local FinalPos =,Y,Z)


	print("moving to")

PathfindingService and Path APIs have no such signal. PathfindingService is only responsible for generating paths based on agent parameters while the Path object is responsible for giving you the positions created to form the path and occlusion support.

Sounds like you’re thinking about MoveToFinished as far as determining when the Humanoid finishes moving to a certain point. As far as checking when the humanoid moves to the last point in a path, you have to write that part yourself.

1 Like

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