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
|
  |
| Joined: 08 Feb 2010 |
| Total Posts: 2937 |
|
| |
|
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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 12 Jun 2014 02:10 AM |
| Thanks for the credit, accomplish. |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2014 02:11 AM |
| Why not just have both team spawns neutral |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 12 Jun 2014 02:19 AM |
Because lobby Because 7 vs 1 |
|
|
| Report Abuse |
|
|
|
| 12 Jun 2014 02:21 AM |
| oh yeah cnt gave me that one use it it works perfectly |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| Joined: 08 Feb 2010 |
| Total Posts: 2937 |
|
| |
|
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
|
  |
| 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
|
  |
| Joined: 08 Feb 2010 |
| Total Posts: 2937 |
|
| |
|
Faxu
|
  |
| Joined: 08 Feb 2010 |
| Total Posts: 2937 |
|
|
| 12 Jun 2014 06:05 PM |
| Never mind, fixed it. Works now. |
|
|
| Report Abuse |
|
|