How can I make an NPC memorize the paths it takes through PathFinding?

Hello DevForum! I am testing an NPC with pathfinding through a maze, and I want it to somehow remember the routes and paths it takes throughout the maze. Is this possible?

Here is my script:

local pfs = game:GetService("PathfindingService")
local goal =, 0.638, -110)
local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = pfs:CreatePath()
path:ComputeAsync(torso.Position, goal)
local waypoints = path:GetWaypoints()

for i, waypoint in pairs(waypoints) do
	local circle ="Part")
	circle.Shape = "Ball"
	circle.Material = "Neon"
	circle.Size =,0.5,0.5)
	circle.Position = waypoint.Position +,2,0)
	circle.Anchored = true
	circle.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))
	circle.CanCollide = false
	circle.Parent = workspace
	if waypoint.Action == Enum.PathWaypointAction.Jump then


If your confident that the path was made successfully, you could get those waypoints like you did with waypoints = path:GetWaypoints(), and store it to another variable like oldPath = waypoints. The path calculated will be there in oldPath until you need it again, giving you that “path from memory.”