Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-3

How do you count how many players are in a team?

Asked by 10 years ago

I'm trying to make an FPS game that has team balance

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Well, to do this then you can make a table for each TeamColor, iterate through the players and insert them into a table corresponding to their TeamColor, and then check the number of indexes in each table.

(Sorry I couldn't explain this better..)

Example;

local red = {} --Red team
local blue = {} --blue team
local green = {} --green team

--Sort the players--
for i,v in pairs(game.Players:GetPlayers()) do
    --Check teamcolor, and sort accordingly--
    if v.TeamColor == game.Teams.Red.TeamColor then
        table.insert(red,v) --Sort player
    elseif v.TeamColor == game.Teams.Blue.TeamColor then
        table.insert(blue,v)
    elseif v.TeamColor == game.Teams.Green.TeamColor then
        table.insert(green.v)
    end
end

--Check amount of indexes--

local numRed = #red
local numBlue = #blue
local numGreen = #green

print("There are "..tostring(numRed).." players on the Red team")
print("There are "..tostring(numBlue).." players on the Blue team")
print("There are "..tostring(numGreen).." players on the Green team")
0
Thanks! I looked at the script to get a better understanding supermarioworld323 45 — 10y
Ad

Answer this question