Hello there!
I currently need to know how to make balanced teams, Player cant not choose teams so I need balance them for eg. Player1 will be in Red team and Player2 will be in blue team and Player3 will be in Red Team, Thanks for any help!
If the teams only need to be assigned once, having the AutoAssignable
property enabled for those Teams will automatically assign players to the one with the least amount of players upon joining.
If that doesn’t match your use case, there’s a fantastic Developer Hub Article about this that may provide some insight for how that could be achieved.
Additionally, here’s some Developer Forum threads that could provide some more value:
No the teams are tables, Any what you said and sent is useless for me
Please search this before making a new post on it due to already existing ones.
local Teams = {
["Red"] = {},
["Blue"] = {}
}
local Participants = {"Player1", "Player2"}
function GetSmallestTeam(Team)
local Lowest = nil
for Index, Team in pairs(Teams) do
if Lowest == nil then Lowest = Team continue end
if #Team < #Lowest then
Lowest = Team
end
end
return Lowest
end
function BalanceTeams(Teams, Participants)
for TeamName, Team in pairs(Teams) do
Teams[TeamName] = {}
end
for Index, Player in pairs(Participants) do
table.insert(GetSmallestTeam(Teams), Player)
end
end
BalanceTeams(Teams, Participants)
print(Teams)
something like this should help
2 Likes