IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 12:22 PM |
How would I implement the math.random into my team rebalance so that it doesn't always put the players on the exact same team they were on previously? Basically once the script is connected, it's sorts the players (apart from lavender team players) into the Red and Blue teams. When I want to connect the function again, it puts the players in exactly the same coloured teams? I've been struggling with this for the past 2 days now, not sure what to do! Would really appreciate help?
Here is the code:
function randomiseteam() for i, v in pairs( Game.Players:GetChildren( ) ) do if v.TeamColor ~= BrickColor.new("Lavender") then if i % 2 == 0 then v.TeamColor = BrickColor.new( "Bright red" ) else v.TeamColor = BrickColor.new( "Bright blue" ) end v:LoadCharacter() end end end
Would really appreciate some help please! |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2013 12:25 PM |
| http://wiki.roblox.com/index.php/RebalanceTeams_(Method) |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 12:29 PM |
| Erm, haha? So how would I implement that method into my script? |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2013 12:31 PM |
| i think it's game.Teams.THETEAMHERE:themethod() |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 12:34 PM |
| What does it mean by "this method does not appear to work as expected" |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|
|
| 06 Jun 2013 01:54 PM |
| You mean on the wiki? ignore it |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 02:26 PM |
| I just need some help sorting out my script so it doesn't continually put players on the same team each time it connects? People suggested a math.random so it randomly chooses some players and puts them on other team etc but I don't get it? |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2013 02:34 PM |
| Make a list with all the players, scramble the order of it's members, and TADAM appy your script to it |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 06 Jun 2013 02:45 PM |
function scrambleTeams() redTeam = {} blueTeam = {} teams = {redTeam,blueTeam}
players = game.Players:getChildren()
while wait() do for key, value in pairs(teams) wait() rand = math.random(1,#players) table.insert(value, players[rand]) table.remove(players, players[rand]) if #players == 0 then return end end
end
That may not be right (i'm kinda derping) but something like that ;) |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 02:59 PM |
| Ah thank you!!! I'll try this soon :D |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:02 PM |
Within the redTeam, should I do game.Teams.Red? or? |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 06 Jun 2013 03:05 PM |
| Yeah reference your actual teams. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:05 PM |
| Alright thanks, I'll do that now. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:06 PM |
| Also you forgot a "do" on that for line :p |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 06 Jun 2013 03:07 PM |
| Told you i was derping lawl. |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
| |
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:42 PM |
| bad argument error #2 to 'remove' |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:43 PM |
That is what it says on the remote error monitoring.
Line 100:
table.remove(players, players[rand]) |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 06 Jun 2013 03:46 PM |
oops.
table.remove(players, rand) |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
|
| 06 Jun 2013 03:53 PM |
| I tested it, and there was no error displayed in the remote error, BUT, nothing happened, me and my tester didn't get sorted into a team. |
|
|
| Report Abuse |
|
|
magnalite
|
  |
| Joined: 18 Oct 2009 |
| Total Posts: 2467 |
|
|
| 06 Jun 2013 04:02 PM |
Put this at the end.
for key, value in pairs(redTeam) do value.TeamColor = BrickColor.new("Bright red") end
for key, value in pairs(blueTeam)do value.TeamColor = BrickColor.new("Bright blue") end |
|
|
| Report Abuse |
|
|
IceOrb
|
  |
| Joined: 02 May 2010 |
| Total Posts: 1206 |
|
| |
|