Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I insert a value with a key into a table using table.insert?

Ok so I want to insert a value with a key into a table, like so:

local Test = {}
table.insert(Test,["Test1"] = {"Test Table"})

But it always gives me a syntax error. How would I do this?

1 answer

✓ Accepted answer

table.insert is just a normal function -- you give it values, not syntax constructs.


However, it is only used for inserting at the whole numbered indexes. Just set:

Test["Test1"] = {"Test Table"}
-- or, equivalently
Test.Test1 = {"Test Table"}

If it was a number index, using table.insert would look like this:

table.insert(Test, 5, {"Test Table"})

1 comment

0

Thanks! Really appreciate your help

This discussion is preserved as it was. New answers, comments, and votes are closed.