How do I get a table of the players on multiple teams?

I know how to do
game.Teams.Team1:GetPlayers()
but what if I want a table of the players in two teams? Also,
local Teams1and2 = game.Teams.Team1:GetPlayers() and game.Teams.Team2:GetPlayers()
doesn’t work.

Create a variable by taking the players from team 1 and team 2, as you did above. Create a table. (Which is done as follows): local table = {}, and then use the command table.insert() to insert the players into the table. I think this is what you want.

Is this correct?

local function getPlayersInRound()
local table = {}
local Campers = game.Teams.Campers:GetPlayers()
Campers = table.insert
local Killer = game.Teams.Killer:GetPlayers()
Killer = table.insert
return table
end

No, table.insert works like this: table.insert(table, Killer)

The first parameter “table” means the name of the table where you are going to insert something.
And killer (second parameter) means what you are going to insert into the table.

How about this?

local function getPlayersInRound()
local playersInRound = {}
local Campers = game.Teams.Campers:GetPlayers()
local Killer = game.Teams.Killer:GetPlayers()
table.insert(playersInRound,Campers)
table.insert(playersInRound,Killer)
return playersInRound
end

Yes! This should work.
30CharLimit*

No, you are half-correct in getting the lists of players for each team. Now it’s just a matter of merging the two arrays.

local function getPlayersInRound()
	local playersInRound = {}
	local campers = game.Teams.Campers:GetPlayers()
	local killer = game.Teams.Killer:GetPlayers()
	-- Add everyone in the first team to the final list.
	for _, player in ipairs(campers) do
		table.insert(playersInRound, player)
	end
	-- Then add everyone in the second team.
	for _, player in ipairs(killer) do
		table.insert(playersInRound, player)
	end
	return playersInRound
end
1 Like

As @blokav mentioned, you can do this:

function get_Round_Players()
	local campers = game.Teams.Campers:GetPlayers();
	local killers = game.Teams.Killers:GetPlayers();
	local total = {};
	
	for _, v in ipairs(campers) do
		table.insert(total, #total + 1, v)
	end
	
	for _, v in ipairs(killers) do
		table.insert(total, #total + 1, v)
	end
	
	return total
end;
local function getPlayersInRound()
	return {game.Teams.Campers:GetPlayers(),game.Teams.Killer:GetPlayers()}
end

I see no reason putting those two teams of player in a same table, you will almost always be returned with the same results as plrs:GetPlayers()
You should just use if checks to see if the player is not in a certain team if they can be any team outside those 2.

1 Like

Thank you so much for your help. While this was the particular solution that worked for me, I still appreciate everyone’s support.