How can I create 2 keys with same name in table without one overwriting?

So lets say that I have a table, and I want to add two new keys Item.

local Table = {}

local Items = {
	['Item'] = nil
}

They should both share the same key name Item. Currently, I’m using a workaround to make the keys named correctly. The following function clones the key from table Items to Table:

local RequestedName = 'Item'
local RequestedItem = Items[RequestedName]
local TempData = table.clone(RequestedItem)
Table[RequestedName] = TempData
table.remove(Table, Table[TempData])

This works for one use, but my problem lies in the fact that this will not create the second key with the same name, but instead overwrite the original key. How could I make this work as intended?

Any help would be much appreciated!

You can hold it as separate tables.

local Items = {
	{Name = "Item"},
	{Name = "Item"}
}

Also, assuming this is some sort of inventory system, you could simply create an amount for a saved item instead of a whole new table, unless the items are planned to have varying stats.

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