How do i make a dictionary with the table.insert function? Like when i have a table products and i want to fill it with the amount and price of each product through a script.
If you have a bunch of product names, and values for each, you can set up a dictionary like this to hold that info:
local Products = { Banana = { Amount = 5; Price = 4.5; }; ["Orange Peel"] = { Amount = 666; Price = 6.7; }; --etc }
An then, if you wanted to add a new product with a script, you could do something like this:
Products[Apple] = { Amount = 3; Price = 2.3; }
To then retrieve information about a product, you can index the dictionary like this:
local BananaPrice = Products.Banana.Price print(BananaPrice) --> 4.5
Or, if there are spaces in the name of the product, you could do it like this instead:
local PeelAmount = Products["Orange Peel"].Amount print(PeelAmount) --> 666
Hope this helps!