else
local teamindeciso = teams.Neutral
local tablasoo = {}
for i , playersofteam in pairs(teamindeciso:GetPlayers()) do
table.insert(tablasoo,playersofteam)
local playerservice = game:GetService("Players")
local pillados playerservice:GetPlayers(tablasoo)
end
What happens is that I have a team selection system and I want that if one or a group of players do not choose a team, I distribute them in an order to each team. There are 2 teams and I want the maximum number of players for each team to be 2, so let’s assume that there are 4 of us on a server, then 3 vote but since I didn’t want to vote, it simply puts me in a team that lacks players if you would be so kind, could you give me an example?
one team is 1 and the other is 2…
as a curious fact I made a team called neutral that has the autoselected activated
I understand clearly and I would do that but the problem is if one of those teams is full what I need is to distribute the players of the neutral team to the teams with less than 2 players
Well, in that case, you can use a for loop with a counter that adds up for every player currently on the team
If you add in this function
local teams = game:GetService("Teams")
local function playersOnTeam(playersTable, team: Team)
local plrCounter = 0
for _, ply in pairs(playersTable) do
if ply.Team == team then
plrCounter += 1
end
end
return plrCounter
end
Then you can replace the current code inside of the else statement with this:
local teamindeciso = teams.Neutral
local tablasoo = {}
for i , playersofteam in pairs(teamindeciso:GetPlayers()) do
table.insert(tablasoo,playersofteam)
local playerservice = game:GetService("Players")
local pillados playerservice:GetPlayers(tablasoo)
local plrsOnTeam1 = playersOnTeam(tablasoo, teams.FirstTeam)
if plrsOnTeam1 > 2 then
playersofteam.Team = teams.OtherTeamName
end
end
And before I forget, here is the post where the concept of the code I wrote came from:
The code wasn’t entirely my idea. I want to give them sufficient credit, as there are multiple ways to do this, and I remembered this post from a good while ago, therefore credit should go to them. (it was a topic I had bookmarked while at school for me to help later, but they got the solution first.)