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
I am not sure how the team service works with everything, but this script checks how many children are in a instance
1 | local count = 0 |
2 | for i,v in pairs ( "DirectoryToThing" ):GetChildren()) do |
3 | count = count + 1 |
4 | end |
5 | print (count) |
6 | --instead of print you could do whatever you want with the total |
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
01 | local AliveTeam = game.Teams.AliveTeam -- the team |
02 |
03 | function GetAmountOsPlayersInTeam(Team) |
04 | local Total = 0 |
05 | for _,Player in pairs (game.Players:GetChildren()) do |
06 | if Player.Team = = Team then |
07 | Total + = 1 |
08 | end |
09 | end |
10 | return Total |
11 | end |
12 |
13 | wait( 4 ) -- wait for player to load in |
14 | print (GetAmountOsPlayersInTeam(AliveTeam)) -- just to test |
15 |
16 | -- you can use the function in another way |
17 | if GetAmountOsPlayersInTeam(AliveTeam) > 0 then |
18 | print ( "We have more then 0 playe in the game" ) |
19 | end |
i hope this helps you