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

How would I find the amount of players in a team?

Asked by 9 years ago

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

0
These are parts of the script, there is an end on the if statement. Grenaderade 525 — 9y
0
Before downvoting my answer, want to tell me why it doesn't fit your 'need'? DigitalVeer 1473 — 9y
0
I didn't downvote. Grenaderade 525 — 9y

1 answer

Log in to vote
3
Answered by 9 years ago

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

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

0
Why was this downvoted? This answers the OP's question. DigitalVeer 1473 — 9y
0
I upvoted yours becuz I kinda felt bad for ppl downvoting u. groovydino 2 — 9y
0
Thanks. Someone is going around down-voting all my posts. DigitalVeer 1473 — 9y
0
Where it says tColor, do I put the color of the color of the team there? Grenaderade 525 — 9y
View all comments (16 more)
0
When you call the function, you put the teamColor. I'll edit my post so you see what I mean. DigitalVeer 1473 — 9y
0
Wait, I see, I don't need to. I saw the part where it said "Playing" Grenaderade 525 — 9y
0
So now, if I want it to see if there is 1 player, how would I do that? Where would I put the part of the script where that 1 player gets 25 points? Grenaderade 525 — 9y
0
I edited again. DigitalVeer 1473 — 9y
0
Oh, no.. Not player points, the points inside a leaderboard. Grenaderade 525 — 9y
0
Edited Again :\ DigitalVeer 1473 — 9y
0
Alright! Finally. Grenaderade 525 — 9y
0
I'm sorry to say this but... I need to fix one part of the script to see if it works. How would you access all player's playergui? Grenaderade 525 — 9y
0
Since I want to do something with the textlabel inside of the screengui, how would I do that? (I'm sorry I'm not really good with this kind of scripting) Grenaderade 525 — 9y
0
Alright. What is the name of the ScreenGui and is the Textlabel directly inside it or is it inside a frame thats inside ScreenGui? DigitalVeer 1473 — 9y
0
TextLabel inside screengui. (...Intermission.TextLabel) Grenaderade 525 — 9y
0
Edited Again :P DigitalVeer 1473 — 9y
0
I tried it, the whole script didn't do anything, want me to put the whole script? Grenaderade 525 — 9y
0
Which script? DigitalVeer 1473 — 9y
0
1 Problem with the game script, I'll put it in a separate question: https://scriptinghelpers.org/questions/16301/random-spawning-not-working Grenaderade 525 — 9y
0
Can you guys do me a favor and down-vote everything of this guy: https://scriptinghelpers.org/user/3089/XToonLinkX123 DigitalVeer 1473 — 9y
Ad

Answer this question