How to make a Table like this?

How to create a table like this, but for each player:

local Table = {
	["PlayerName"] = {
		["TimeSpent"] = 0,
		["InGroup"] = false,
	} 
}

So for example, when someone new joins it’d be as such:

local Table = {
	["PlayerName"] = {
		["TimeSpent"] = 0,
		["InGroup"] = false,
	},
	
	["PlayerName2"] = {
		["TimeSpent"] = 0,
		["InGroup"] = false,
	}
}

And so on.

Thanks in advanced!

Easy:

local Players = game:GetService("Players")

local PlrsTable = {}

local function OnPlayerAdded(Player)
    PlrsTable[Player.Name] = {
        ["TimeSpent"] = 0,
        ["InGroup"] = false
    }
    print(PlrsTable)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

Whenever a new player joins, the table will get populated with the data you showed

2 Likes

I thought it was something easy, but was unable to properly think on how it works lol.

Thanks very much bro.

Remember to remove the table entry inside of a PlayerRemoving event.

1 Like