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'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
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
How about do "#Directory:GetChildren()"
That does work but theres a better way, still a helpful answer.
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
if you have any question about this script ,ask.
uh so if there is 1 players in the alive team I want to teleport them to a part called "intermission"
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
this is the script
Note: this is not the best way to do it
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
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.
Shut up just let him
This was my last choice.