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

How to check if there are players on a team?

Asked by 5 years ago

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

0
Use a loop Mr_Unlucky 1085 — 5y
0
Btw send an answer not a comment mewant_taco 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

0
Ok thanks mewant_taco 17 — 5y
Ad

Answer this question