Collapse Sidebar


This function computes a Path from a start position to an end position. This function is not automatically called when a path is created and must be invoked each time the path needs to be updated.

Once the Path is computed, it will have a series of waypoints that, when followed, can lead a character along the path. These points are gathered with the Path/GetWaypoints function.

See also

  • articles/Pathfinding, provides an in-depth pathfinding walkthrough


Name Type Default Description

The world position where the computed path begins

The world position where the computed path finishes


Return Type Summary

No return

Code Samples

Using the Pathfinding Service

The code sample below explores how to move an NPC along a more complex path or around obstacles.

-- Create a path with the parameter set
local agentParams = {
	AgentRadius = 2.0,
	AgentHeight = 5.0,
	AgentCanJump = false

local path = PathfindingService:CreatePath(agentParams)

-- Listen to path blocked events

-- Compute the path
path:ComputeAsync(humanoidPos, targetPosition)

-- When the path is blocked...
function OnPathBlocked(blockedWaypointIdx)

    -- Check if the obstacle is further down the path
    if blockedWaypointIdx > currentWaypointIdx then

        -- Recompute the path
        path:ComputeAsync(updatedHumanoidPos, targetPosition)
        if path.Status == Enum.PathStatus.Succeess then

            -- Retrieve update waypoint list with path:GetWaypoints()
            -- and Continue walking towards target
            -- Error, path not found