I don’t know if this goes in this topic but. I’m trying to make my Four teams only have 24 or less people on it, So the Teams are equal.
But I can’t seem to figure that out I spend at least a day trying to figure it out and I can’t
I don’t know if this goes in this topic but. I’m trying to make my Four teams only have 24 or less people on it, So the Teams are equal.
But I can’t seem to figure that out I spend at least a day trying to figure it out and I can’t
There is a developer hub article on this:
This might help.
If you go to explorer on a team, Roblox should have a automatic handler
for equal teams. I forgot what it’s called but it’s one of the only things in
explorer for a team.
This is untested, but should be the general method. This basically shuffles the player array itself, then uses modulus to assign the players a TeamColor. It’s not perfect, but it’s pretty good in my opinion. Since Lua isn’t 0 indexed, it places players on the 2nd team first. If this isn’t the answer you were looking for please look at. Team Balancing
local random = Random.new()
-- Taken from: https://stackoverflow.com/questions/35572435/how-do-you-do-the-fisher-yates-shuffle-in-lua
function shuffle( tInput )
local tReturn = {}
for i = #tInput, 1, -1 do
local j = random:NextInteger(1, i)
tInput[i], tInput[j] = tInput[j], tInput[i]
table.insert(tReturn, tInput[i])
end
return tReturn
end
local teams = {TeamObject1, TeamObject2, TeamObject3, TeamObject4}
local players = shuffle(game.Players:GetPlayers())
for i, player in pairs(players) do
player.TeamColor = teams[(i % #teams) + 1].TeamColor
end