Help with Table

I am trying to call a inserted item inside a table to be called back out and parented back into the Workspace of the game. But I keep getting errors.

Picture of Item Setup:
Screenshot 2022-11-05 232744

Line in my script that inserts items into table:

local StoredPurchase = {}

for _,Item in pairs(Purchase:GetChildren()) do
	table.insert(StoredPurchase, Item)

	Item:Destroy()
end

Line in my script that im trying to reinsert into Workspace:

for _,Item in pairs(StoredPurchase) do
		if Item.Name == ButtonName then
			Item.Parent = Purchase
		end
	end

You destroy the item, causing it to not be able to be reparented.

But. Why would that matter? Because it stored a copy of the item into the table.

If you wanted it like that, you would probably have to use a clone of the item. Inserting the item into a table doesn’t create a whole new item, rather puts a reference of the item into a table, making destroying it equivalent to destroying the item inside of the table.

1 Like

It didn’t store a copy in the table, it stored a reference to the object. Whatever you do to the object, it will be referenced in the table.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.