How would I add two values per value in a table

I have a round-based game I am working on. Im trying to store the player’s name and how long the player has been in a round.

what Im trying to do is this.

table.insert(table, players time in round and players name) , but the thing is I dont know how to add two values for one value.

dictionary


local dictionary = {
	player1 = {
		Coins = 50,
		Diamonds = 10
	},
	player2 = {
		Coins = 30,
		Diamonds = 5
	}
}

only read the thread title

You can create tables with two values in the main table.

local Players = game:GetService("Players")
local plrs = Players:GetPlayers()
local numOfPlayers = #plrs
local roundTable = table.create(numOfPlayers)
for i, plr in ipairs(plrs) do
    table.insert(roundTable, {plr.Name, timeInRound})
end

You could also do this

local roundTable = table.create(numOfPlayers*2)
for i, plr in ipairs(plrs) do
    roundTable[i*2-1], roundTable[i*2] = plr.Name, timeInRound
end

@Alm_st 's suggestion may be more organised, though.

1 Like