Adding values to a table within a table

Good afternoon.

I’m trying to insert values into a table within a table. While it initially does work, it keeps the table inside restricted to having only one value. Every time I try adding a value again, only one value remains inside.

local plr_data = {
		["Coins"] = Player.PLR_DATA.Coins.Value,
		["Gems"] = Player.PLR_DATA.Gems.Value,
		["SerialIds"] = {}
	}
	if item1 then --Possible id to add to the serial library.
		table.insert(plr_data["SerialIds"], item1)
	end

Thanks for helping out (or reading).

1 Like

The inner table is frozen, which prevents you from adding values to it.

The fix is to create a new instance of it (the inner table) and insert it to the outer table

Example:

local outerTable = {}
local innerTable = {}  -- Create a new instance of the inner table
outerTable.innerTable = innerTable  -- Assign the inner table to the outer table

-- Insert a value into the inner table
table.insert(innerTable, "hello")

-- Now you can add more values to the inner table
table.insert(innerTable, "sup")

print(innerTable[2])  -- Output: sup