How do I make a table of players for every team?

I have made this, but it only makes one table:

     for i, z in pairs(teams:GetChildren()) do
     	local teamTable = {}
     	local team = z:GetPlayers()				
     	for i =1,#team do
    		table.insert(teamTable, team[i])
     	end

Although I may have used the code above incorrectly.
Any help is appreciated!

So you’re trying to make a table that contains tables of players? This might be what you want:

local teamContainer={} --establish table to contain teams
for i,v in pairs(teams:GetChildren() do --cycle through teams
    teamContainer[v.Name]=v:GetPlayers() --create a new table inside of TeamContainer
                                         --that holds the team's players
end
6 Likes