Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if there are players on a team?

So, im making a game where each player has a castle and i wanted to make the castle picking automatic. And to do so (i think that) i have to know when a team has player on. So, how do i check if a team as any players? Btw here's the script:


local player = game.Players.LocalPlayer
local redTeam = game.Team.redCastle
local blueTeam = game.Team.blueCastle
local greenTeam = game.Team.greenCastle
local yellowTeam = game.Team.yellowCastle

if -- this is where i think it is going to check the teams (here it checks if all teams are empty -- then
  --btw i dont know how to change a player teams eitheir, sorry im nub --
elseif -- teamCheck -- then
  -- Change team --
elseif -- teamCheck -- then
  -- Change team --
elseif -- teamCheck -- then
  -- Change team --
end


Thx for reading this. :3

2 comments

0

Use a loop

0

Btw send an answer not a comment

1 answer

✓ Accepted answer

The Team class has a :GetPlayers() function kind of like the Players service, but returns an array of players in the team. The Team class also has a PlayerAdded and PlayerRemoving event if you need those.

if #team:GetPlayers() < 1 then
    -- ...
end

The # is the length operator, it returns the length of a table or string, and in this case if the length is 0 that is because there is no players in the team. If you want to check if there is players just do #team:GetPlayers() > 0.


####Don't forget to accept if this helps

1 comment

0

Ok thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.