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: How To Randomly Sort Into 2 Teams

Previous Thread :: Next Thread 
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 01:11 AM
How would I randomly sort any amount of people into 2 teams? I keep trying and I can't figure out a way to do this.
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 01:19 AM
boouooomuomoop
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
12 Jun 2014 01:23 AM
local table = game.Players:GetPlayers()

repeat
local index = math.random(#table)
table[math.random(index)].TeamColor=BrickColor.new("red") --idc if this is wrong you get my point
table.remove(tabel, index)
if #table~=0 then
index = math.random(#table)
table[math.random(index)].TeamColor=BrickColor.new("blue") --idc if this is wrong you get my point
table.remove(tabel, index)
end
until #table == 0
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 01:38 AM
So how would I put this into a function? By the way, I already have my teams made.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
12 Jun 2014 01:41 AM
lold jst put function makethisthingnob()at beginning and end at end of the code
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 01:53 AM
Hm. I tested this by myself, using this function:


function teamsort()
repeat
local index = math.random(#table)
table[math.random(index)].TeamColor = BrickColor.new("Orange")
table.remove(tabel, index)
if #table~=0 then
index = math.random(#table)
table[math.random(index)].TeamColor = BrickColor.new("Red")
table.remove(tabel, index)
end
until #table == 0
end


But it didn't work. I suspect it's because of line 4 and 8 not actually finding the teams. Let's say the teams are called "Robots" and "Aliens" (they actually aren't). What would I do then?
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
12 Jun 2014 01:55 AM
I took the one from my game script. Here ya go!

function Assign()
local half = math.floor(Game.Players.NumPlayers/2)
local Plyrs = Game.Players:GetPlayers()
for i = 1, #Plyrs do
local rndom = table.remove(Plyrs, math.random(#Plyrs))
if i <= half then rndom.TeamColor = BrickColor.new(TeamColorHere)
else rndom.TeamColor = BrickColor.new(TeamColorHere)
end
end

end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
12 Jun 2014 02:05 AM
Um brickColor.new("Red") and BrickColor.new("Orange") dont exist.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Jun 2014 02:10 AM
Thanks for the credit, accomplish.
Report Abuse
Scripterity is not online. Scripterity
Joined: 30 Mar 2014
Total Posts: 677
12 Jun 2014 02:11 AM
Why not just have both team spawns neutral
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
12 Jun 2014 02:19 AM
Because lobby
Because 7 vs 1
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
12 Jun 2014 02:21 AM
oh yeah cnt gave me that one use it it works perfectly
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 02:24 AM
So with a bright orange team and a bright red team would this work?


function teamsort()
local half = math.floor(Game.Players.NumPlayers/2)
local Plyrs = Game.Players:GetPlayers()
for i = 1, #Plyrs do
local rndom = table.remove(Plyrs, math.random(#Plyrs))
if i <= half then rndom.TeamColor = BrickColor.new(106)
else rndom.TeamColor = BrickColor.new(21)
end
end
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Jun 2014 02:27 AM
if those brick color numbers are correct, yes. You could also just use a string to make it easier.

BrickColor.new("Bright orange") and BrickColor.new("Bright red") instead of the numbers.
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 02:36 AM
Ok, it works. Thanks!
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 02:44 AM
Wait... never mind, I found an error. It's on line 5 which says:


local rndom = table.remove(Plyrs, math.random(#Plyrs))


The error says:


attempt to call field 'remove' (a nil value)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
12 Jun 2014 02:46 AM
Let me guess... You defined a variable named "table"
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 06:01 PM
^ Nope.
Report Abuse
Faxu is not online. Faxu
Joined: 08 Feb 2010
Total Posts: 2937
12 Jun 2014 06:05 PM
Never mind, fixed it. Works now.
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