generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How could I systematically place players into teams?

Previous Thread :: Next Thread 
ColorfulBrendon is not online. ColorfulBrendon
Joined: 28 Jul 2010
Total Posts: 23556
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
ColorfulBrendon is not online. ColorfulBrendon
Joined: 28 Jul 2010
Total Posts: 23556
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
ColorfulBrendon is not online. ColorfulBrendon
Joined: 28 Jul 2010
Total Posts: 23556
14 Nov 2015 05:05 PM
b1
Report Abuse
TheComputerist is not online. TheComputerist
Joined: 28 Oct 2011
Total Posts: 695
14 Nov 2015 05:07 PM
I think you forgot an end

"Lua is coding. Lua is life" - TheComputerist
Report Abuse
Casualist is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image