Codectionary / Developer documentation / Luau

PathfindingService paths

Compute navigable waypoints around obstacles.

Why use PathfindingService?

PathfindingService can calculate a route for an agent through the world. Computing a path does not move a character automatically; movement logic must use the returned waypoints.

Try it in Roblox Studio

Put this Script in ServerScriptService in a Studio map with a route between the two coordinates. Change the positions to points your map can actually reach.

Syntax

path:ComputeAsync(startPosition, destination)

Examples

PathfindingService paths

Compute and inspect a route without moving an NPC.

local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
local ok, err = pcall(function()
    path:ComputeAsync(Vector3.new(0, 3, 0), Vector3.new(20, 3, 0))
end)
if not ok then
    warn("Path computation failed:", err)
elseif path.Status == Enum.PathStatus.Success then
    for _, waypoint in path:GetWaypoints() do
        print(waypoint.Position)
    end
else
    warn("No usable path:", path.Status.Name)
end
  1. CreatePath makes a Path object, and ComputeAsync calculates a route for the start and destination.
  2. pcall catches a computation error; Status separately reports whether a usable path was found.
  3. GetWaypoints returns positions to follow. The script only prints them, so an NPC does not move yet.

Best practices

  • Handle both thrown errors and unsuccessful path status.
  • Recompute routes when the destination or environment changes substantially.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading