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
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
.