I'm making a gameplace where in the games there has to be 1 player left to get points, but I don't know how to locate the amount of players in a team.
pteam = game.Teams.Playing:GetChildren()
...
if pteam.NumPlayers == 1 then pteam.leaderstats.Points.Value = pteam.leaderstats.Points.Value + 25
This is in a script
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) -- Prints number of people on team
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
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