How do I insert a key & value into a table

Pretty self explanatory, been messing around for how I would add to a table such as:
local toolsIndex = {} a value and a key, I want the table to look like this { Key = 1 } and so on, { Key = 1, Key2 = 2} Tried the Developer Hub, didn’t find what I need… anyone mind enlightening me?

1 Like

There are a few ways you can do this. Firstly, you can set it as such:

toolsIndex[Key] = val

Or, alternatively,

toolsIndex.Key = val

Both are the same as to my knowledge however the first is preferred in normal programs and the second is mainly used within modules.

7 Likes

Put this in scripting support.

I thought I did, my bad… :expressionless: very helpful btw

thank you! you enlightened me :smiley: