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 » Scripting Helpers
Home Search
 

Re: Trying to make this team randomizer always be equal...

Previous Thread :: Next Thread 
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
27 Aug 2014 04:40 PM
So this team randomizer I made works fine, but the thing is with it being random it will be unequal most of the time, so I need you guy's help to make it so it will always be equal.


while true do
wait(1)
for i,v in pairs(Game.Players:GetPlayers()) do
team = {"Bright yellow", "Dark stone grey"}
v.TeamColor = BrickColor.new(team[math.random(#team)])
end
wait(3)
for i,v in pairs(Game.Players:GetPlayers()) do
v.TeamColor = BrickColor.new("White")

end

end
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
27 Aug 2014 04:42 PM
hey!:)
what i would do is check the numbers on each team
if equal then do a random
if one is more than the other then put that player on the team will less players

want me to try that for you?
Report Abuse
ROBOFROG is not online. ROBOFROG
Joined: 04 Jan 2009
Total Posts: 1519
27 Aug 2014 04:44 PM
This may not be the best and most efficient way, but it'll work.

Create an integer value for each team, and check if they are equal to one another. If not, have it increase the lowest value's team by one until all players are sorted.
Report Abuse
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
27 Aug 2014 04:44 PM
It would be great if you could try it for me <3

Report Abuse
tyzone is not online. tyzone
Joined: 16 Aug 2008
Total Posts: 1726
27 Aug 2014 04:55 PM
if i ~= #game.Players:GetPlayers() or #game.Players:GetPlayers()%#team ~= 0 then
v.TeamColor = BrickColor.new(team[(i%#team+)1])
else
v.TeamColor = BrickColor.new(team[math.random(#team)])
end



The first one will put the first player in the first team, then the second player in the second team, and so on.

If, when you get to the last i, the teams are uneven, the same thing happens, thus making the teams even.

If, when you get to the last i, the teams are already even, the last player is put in a random team.
Report Abuse
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
27 Aug 2014 04:56 PM
@ROBOFROG I understand what you are saying, but I am not quite sure how to do that.
Report Abuse
tyzone is not online. tyzone
Joined: 16 Aug 2008
Total Posts: 1726
27 Aug 2014 04:59 PM
Following ROBOFROG's method, you'd have to create a variable for each team.

blu = 0
red = 0

If blu == red, pick a random number between 1 and 2. If it's one, switch the player to the first team, and increase blu by one. Otherwise, if it's two, switch the player to the second team, and increase red by one.

If blu < red, switch the player to the first team. Increase blu by one.

If blu > red, switch the player to the second team. Increase red by one.
Report Abuse
legokendall is not online. legokendall
Joined: 07 Aug 2010
Total Posts: 667
27 Aug 2014 05:02 PM
@Tyzone so would it be:

while true do
wait(1)
for i,v in pairs(Game.Players:GetPlayers()) do
team = {"Bright yellow", "Dark stone grey"}
if i ~= #game.Players:GetPlayers() or #game.Players:GetPlayers()%#team ~= 0 then
v.TeamColor = BrickColor.new(team[(i%#team+)1])
else
v.TeamColor = BrickColor.new(team[math.random(#team)])
end
end
wait(3)
for i,v in pairs(Game.Players:GetPlayers()) do
v.TeamColor = BrickColor.new("White")

end

end


To be honest I have no idea what this would do lol, but on line 6 there is an error
Report Abuse
tyzone is not online. tyzone
Joined: 16 Aug 2008
Total Posts: 1726
27 Aug 2014 05:06 PM
I put the parenthesis in the wrong place. Sorry about that.

v.TeamColor = BrickColor.new(team[(i%#team)+1])

If i is an even number, it will return 1.
If i is an odd number, it will return 2.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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