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

How do you check how many players are on a team? [help bro]

Asked by
OFF_S4LE 127
3 years ago
Edited 3 years ago

I'm trying to see how many players are on a team, can someone create a line/if then/function for a script?

My attempt:

if Teams.Alive.GetPlayers == 1 then

0
You need to try it yourself man, first do a script and then if you don't know what is wrong it will be easier to us find the error. Basically you are asking if someone can do it for you but man personally with all my experience don't copy paste scripts, learn yourself, fight yourself, and do it yourself . So do something at least so we can help. LetalNightmare 99 — 3y
0
Shut up just let him iivSnooxy 248 — 3y
0
This was my last choice. OFF_S4LE 127 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

I am not sure how the team service works with everything, but this script checks how many children are in a instance

local count = 0
for i,v in pairs("DirectoryToThing"):GetChildren()) do
    count = count + 1
end
print(count)
--instead of print you could do whatever you want with the total
1
How about do "#Directory:GetChildren()" User#30567 0 — 3y
1
That does work but theres a better way, still a helpful answer. THUNDER_WOW 203 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Here is a function the counts how many players are in the given team it loops through all the players and it check if the player is in the given team if so it add 1 number in to a variable then it returns it

local AliveTeam = game.Teams.AliveTeam -- the team

function GetAmountOsPlayersInTeam(Team)
    local Total = 0
    for _,Player in pairs(game.Players:GetChildren()) do
        if Player.Team == Team then
            Total += 1
        end
    end
    return Total
end

wait(4) -- wait for player to load in
print(GetAmountOsPlayersInTeam(AliveTeam)) -- just to test

-- you can use the function in another way 
if GetAmountOsPlayersInTeam(AliveTeam) > 0 then
    print("We have more then 0 playe in the game")
end

i hope this helps you

0
if you have any question about this script ,ask. asdfghjk9019 225 — 3y
0
uh so if there is 1 players in the alive team I want to teleport them to a part called "intermission" OFF_S4LE 127 — 3y
0
local AliveTeam = game.Teams.AliveTeam function GetAmountOsPlayersInTeam(Team) local Total = 0 for _,Player in pairs(game.Players:GetChildren()) do if Player.Team == Team then Total += 1 end end return Total end function TeleportPlayerInTeamToPart(Team, Part) for _,Player in pairs(game.Players:GetChildren()) do if Player.Team == Team then local Charcter = Player.Character or Pl asdfghjk9019 225 — 3y
0
this is the script asdfghjk9019 225 — 3y
0
Note: this is not the best way to do it asdfghjk9019 225 — 3y

Answer this question