|
| 14 Nov 2015 03:13 PM |
I have a place where teams are randomly selected from a list and then placed into the Teams service. I am trying to make it so during a specific game mode, players will be placed into this list.
I wrote a (non-functioning) script that would, if it worked, place players into teams at random. for _, player in pairs(game.Players:GetPlayers()) do if player then local allTeams = game.Teams:GetChildren() local player = game.Players.LocalPlayer player.Team = allTeams[math.random(1, #allTeams)] end
Even if it worked, I'd like to make it so that it would take into account the amount of players already in a team before placing more players into teams (so that if there is 1 player in one team and 2 players in the other, it would place the next player in the team with less people to balance it)
How could I do that? |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2015 03:14 PM |
Made a mistake in a sentence, "players will be placed into this list." should say "players will be placed into these teams."
|
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Nov 2015 05:07 PM |
I think you forgot an end
"Lua is coding. Lua is life" - TheComputerist |
|
|
| Report Abuse |
|
|
Casualist
|
  |
| Joined: 26 Jun 2014 |
| Total Posts: 4443 |
|
|
| 14 Nov 2015 05:15 PM |
local players = game:GetService("Players"):GetPlayers() local teams = game:GetService("Teams"):GetTeams() for i = 0, #players-1 do table.remove(players, math.random(1, #players)).TeamColor = teams[i%#teams+1].TeamColor end |
|
|
| Report Abuse |
|
|