I'm trying to randomly select a percentage of players to be in one team. I want 20% of the people to randomly be selected for the Red team, 60% to be selected for the Green team, and 10% to be selected for the Blue team.
This is what I have so far, does it work?
players = game.Players:GetChildren() redpercentage = math.floor(#players * 0.2) redteam = math.random(redpercentage, players) greenpercentage = math.floor(#players * 0.6) greenteam = math.random(greenpercentage, players) bluepercentage = math.floor(#players * 0.1) blueteam = math.random(bluepercentage, players)
Also, how could I, persay, select them, so that I could set their team color, give them certain Guis, and give them certain tools, based on their selected color?
local redTeam = {} local greenTeam = {} local blueTeam = {} for a,b in pairs(game.Players:GetChildren()) do local chance = math.random(1,100) if chance <= 0 then table.insert(redTeam,b) elseif chance <= 40 then table.insert(greenTeam,b) elseif chance <= 60 then table.insert(blueTeam,b) end end
I don't know if this was helpful, This is just how I'd randomly insert players into tables(then insert them into teams). You can then do this:
for i = 1,#redTeam do local gui = game.Lighting.Gui:Clone() gui.Parent = redTeam[i].PlayerGui end
and insert Guis or weapons like that.
Hope this helped:
~Sweetepa11fir