✓ Accepted answer
The NumPlayers property is only found under the service Players. To find the number of people on a teams you may have to do a comparison check with the Players TeamColor and the Teams TeamColor.
local function getPlayersOnTeam(tColor)
local plrs = {}
for _, player in pairs(game.Players:getPlayers()) do
if (not player.Neutral) and player.TeamColor == BrickColor.new(tColor) then
table.insert(plrs, player)
end
end
return plrs
end
print(#getPlayersOnTeam(game:GetService("Teams")["Playing"].TeamColor))
If you just want to call the function with only TeamColor, you can do:
local function getPlayersOnTeam(tColor)
local plrs = {}
for _, player in pairs(game.Players:getPlayers()) do
if (not player.Neutral) and player.TeamColor == BrickColor.new(tColor) then
table.insert(plrs, player)
end
end
return plrs
end
local tabOfPlayers = getPlayersOnTeam("Bright Red")
print(#tabOfPlayers)
Checking For One Player
As per your comment, you are interested in finding one Player it seems.
Since we have a table of Players on one team, it's easy to do this!
local function getPlayersOnTeam(tColor)
local plrs = {}
for _, player in pairs(game.Players:getPlayers()) do
if (not player.Neutral) and player.TeamColor == BrickColor.new(tColor) then
table.insert(plrs, player)
end
end
return plrs
end
local num;
local team = game:GetService("Teams")["Playing"];
repeat
local num = (#getPlayersOnTeam(team.TeamColor))
until num ==1
local plrs = getPlayersOnTeam(team.TeamColor)
if plrs[1]:FindFirstChild("leaderstats") then
plrs[1].leaderstats.points.Value = plrs[1].leaderstats.points.Value + 1
end
Accessing everyone's playerGUI & TextLabel
As per your comment, you are interested in accessing everyones PlayerGui.
Believe it or not, this can easily be done with a loop:
for _,player in pairs(game.Players:GetPlayers()) do
if player.PlayerGui:FindFirstChild("Intermission") then
player.PlayerGui["Intermission"].TextLabel.Text = "Intermission Started!"
end
end
Code Above Is Untested
3 comments
These are parts of the script, there is an end on the if statement.
Before downvoting my answer, want to tell me why it doesn't fit your 'need'?
I didn't downvote.