How to add multiple data for a value in tables?

Hi, I’m new to scripting!

So, how do I add this kind of value on a table? Do I still use the table.insert? or is it something different?

and how exactly do I do it?

local playersInLobby = {
{
obj = game.Players.Nick;
playing = true
	};
obj = game.Players.Bob;
playing = true
}

I did look for any sources for this but I don’t see any results regarding this.

1 Like

Yes you can still use table.insert().

hi, but how do I exactly do it?

The usual way: table.insert(yourTable, theValue, pos)

Or if you want the value to just be put at the end of the table, you would do

table.insert(TheTable, TheValue)

that would only work for an array, if this is a dictionary you would do

Table.Key = value

Ex:

local Blah = {
Dog = "the best"
Cat = "boo"
}
-- Add a new value with Cow as the key and idk as the value
Blah.Cow = "idk"

print(Blah.Cow) -- prints idk

Your script is a dictionary, so you would use the second way to insert values.

An alternative to table.insert is:

local t = {}
t.a = 55
– Or:
local x = 66
t[#t+1] = x
for i,v in pairs(t) do
print(i,v)
end

Something like that

local playersInLobby = {}
playersInLobby[plr.Name] = {} -- to prevent thing which I'll tell later
playersInLobby[plr.Name].obj = game.Players.Nick
playersInLobby[plr.Name].playing = true

I hope I got it right, because I tried to find answer too, and found it myself somehow.

but if you try

local playersInLobby = {}
playersInLobby[plr.Name] = {obj = things}

then after you do

playersInLobby[plr.Name] = {playing = true}

then obj will be nil

1 Like