Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

Players in Team

  • This website was created by Roblox members to replace the official forums (because Roblox shut them down) Join us if you like Roblox!

programingsystem

New Member
Reputation: 0 / 0 / 0
Feb 16, 2021
10
0
1
Roblox
oscarzusty
I make a round system, timer and more. But i have a broblem with end of round. I would like the criminals to win after the death of all the players from the police team and vice versa, but I don't know how to check how many players there are in the team.
 

CallMeKY

Moderator
Ultra
Reputation: 6 / 0 / 0
Feb 25, 2018
1,492
39
607
113
Maine, USA
Roblox
CallMeKY
Discord
CallMeKY#5012
I make a round system, timer and more. But i have a broblem with end of round. I would like the criminals to win after the death of all the players from the police team and vice versa, but I don't know how to check how many players there are in the team.
Team Tally Function:
local function getTeamDistribution()
    local teams = {}
   
    for _, player in pairs(game:GetService('Players'):GetPlayers()) do
        local teamName = tostring(player.Team)
        if not teams[teamName] then
            teams[teamName] = 0
        end
        teams[teamName] += 1
    end
   
    return teams
end

-- only use the above function for work; everything below is just a usage example

local function usageExample()
    for teamName, teamCount in pairs(getTeamDistribution()) do
        print(teamName .. ' has ' .. teamCount .. ' players.')
    end
end

while wait(1) do
    usageExample()
end