Table Overflow error

Hello, i am following a JavaScript video on how to make a* pathfinding: video, but i have ran into a problem.

whenever i try to trace back and generate a path, i am receiving an error called “Table Overflow” how could i possible solve this?

if (cur == End) then
			-- Find path
			Path = {}
			local temp = cur
			table.insert(Path, temp)
			while (temp.prev) do
				table.insert(Path, temp.prev) -- The error is on this line
				temp = temp.prev
			end
		end