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

How can I see how many people are on a team?

Asked by 3 years ago
Edited 3 years ago

I need to track the amount of people on teams to determine who wins the round, however it always says that there are zero people on the teams even if that isn't true. I double checked to make sure it was the correct colors for each team. These are not the names for the teams, however, just in case that might be the issue.

blue = 0
red = 0
while wait(1) do
for _,v in pairs(game.Players:GetChildren()) do
    if v.TeamColor.Name == "Crimson" and v.Neutral == false then
        red = red + 1
    elseif v.TeamColor.Name == "Cyan" and v.Neutral == false then
        blue = blue + 1
    end
end

print("There are "..red.." players on the red team and "..blue.." players on the blue team.")
end

New script that comes up with this error message:Workspace.HidingWin:6: attempt to call a string value

local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()
    print("Team " .. team.Name .. " has " .. #players .. " players")
    if team.Name("Hiding").. #players > 0 then
        game.Workspace.HidingWinTestA.Value = true
    end
end

1 answer

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago
local teams = game:GetService("Teams"):GetTeams()
for _, v in pairs(teams) do
    local players = v:GetPlayers()
    print("Team " .. v.Name .. " has " .. #players .. " players")
    if v.TeamColor.Name == "Crimson"  .. #players > 0 then
        game.Workspace.HidingWinTestA.Value = true
    end
end


0
Thank you, however, I added this: "if team.Name("Hiding").. #players > 0 then game.Workspace.HidingWinTest.Transparency = 0" and this error message came up "Workspace.HidingWin:6: attempt to call a string value" Do you know anything about this? Creeperbob16 28 — 3y
0
Oh its because your trying to compare a string JesseSong 3916 — 3y
0
Edit your script so I can help JesseSong 3916 — 3y
0
alr im guessing u mean i should edit the question Creeperbob16 28 — 3y
View all comments (2 more)
0
Edited JesseSong 3916 — 3y
0
Please accept my answer JesseSong 3916 — 3y
Ad

Answer this question