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 = Vector3.new(119, 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 = Instance.new("Part")
	circle.Shape = "Ball"
	circle.Material = "Neon"
	circle.Size = Vector3.new(0.5,0.5,0.5)
	circle.Position = waypoint.Position + Vector3.new(0,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
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	
	humanoid:MoveTo(waypoint.Position)
	humanoid.MoveToFinished:Wait(2)
end

humanoid:MoveTo(goal)

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.”