How do I make a round end when a team has no players left?

I am making a game where a payer needs to pick a colour and try to eliminate all the other players. I want to make it so that when the Players team has no players left the round will end. I am a new scripter and I cant find anything online, I appreciate any help!

This is my script:

while true do
wait(10)
function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor
    if player.Character then --Just in case the character doesn't exist for some reason
        player:LoadCharacter() -- Kills the players' character
    end
end

– Change Teams
for _, player in pairs(game.Players:GetPlayers()) do
setTeam(player, “Players”)
end

– ColourPicker

local Players = game.Players
local Picker = game.Teams.ColourPicker
wait(.5)

plrs = game.Players
local p = plrs:GetPlayers()
local selected_value = math.random(1, #p)
p[selected_value].Team = game.Teams.ColourPicker
p[selected_value]:LoadCharacter()

– end if players die
if game.Teams.ColourPicker:GetPlayers()
– This is where I want it to happen.

– Change Back

wait(180)
function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor
    if player.Character then --Just in case the character doesn't exist for some reason
        player:LoadCharacter() -- Kills the players' character
    end
end

– Change Teams
for _, player in pairs(game.Players:GetPlayers()) do
setTeam(player, “Lobby”)
end
end

If anybody could help me out I would appreciate it! :slight_smile:

Note: Don’t know why it separated sorry.

-- count how many players are on each team
local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
end

With this wiki template, you can check how many teams are there and the current amount of players in it.

Thank you, I will try to modify this!

How would I say “if Players = 0”? Like if the team had no players left?

1 Like

#players is the number of items in the players table.
so if #players == 0 then
print(“no players left”)
end

Uhhh, So your goal is to check when a team have no player left then end the round right?

Sorry about that anyway, You wanted to check if One specific team have no more player right?

Thank you! This is a big help for me!