Help with adding a dictionary to a table

I have a table:

table = {}

and I want to add a dictionary, I would try something like this but I know it won’t work:

table.insert(table, myNum = 9)

Is there a way to achieve something like I said above? I tried making a dictionary beforehand and adding that to the table but now its just a dictionary in a table, I want to add the key and value of the dictionary into the table.
Here is my entire script:

	local inventoryDesc = {}
	for _, v in next, player.inventoryFolder:GetChildren() do
		local name = v.Name
		local dictionary = {[name] = v.Value}
		table.insert(inventoryDesc, dictionary) -- now its just a table and in it a dictionary, I want the key and the value to be saved into the table, not a dictionary inside of inventoryDesc
	end
2 Likes

You can assign a new key directly to the table:

table.someKey = {
apples = 45;
oranges = 2;
}
2 Likes

I can’t do it like that, in my folder there might be different amounts of children with different values and names. Sorry for not mentioning that first.

Then you can declare a new table with whatever key-value pairs that you want, and then assign the key in the other table to whatever you have.

local newTable --//assigned elsewhere

table.blah = newTable
1 Like

You realize you can just do the following, right?

local dict = {}
dict["Key"] = "Value"
print(dict.Key) --Value
4 Likes