|
| 13 Mar 2014 09:51 AM |
So, I need to make a script where 1/3 of the players go to team blue, and 2/3 of the players go to the team red. How would I do that? I looked on the wiki but I didn't find anything. Anyone think they can help? |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2014 10:15 AM |
for i = 1, #game.Players.NumPlayers/3 do local randomplayer = game.Players:GetPlayers()[math.random(1,game.Players.NumPlayers)] if randomplayer.TeamColor ~= (INSERTTEAMCOLORHERE) then randomplayer.TeamColor = (WHATEVERTEAMCOLOR) end end
You get the idea. This does not search again if the player is already that team color. |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2014 10:25 AM |
| Thanks! I can't test it right now since I don't have 3 computers, but I could probably try with 2 |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2014 10:28 AM |
| You don't need 3 computers... Studio -> Tools -> Test -> Start Server (loads, in new window;) Studio -> Tools -> Test -> Start Player (3 times) |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2014 10:36 AM |
| Oh cool! I didn't know about that. Thank you all! |
|
|
| Report Abuse |
|
|
| |
|
Cawlonee
|
  |
| Joined: 03 Mar 2014 |
| Total Posts: 2687 |
|
|
| 13 Mar 2014 11:01 AM |
Evolved script will check the same player again.
You should use a table of players and remove them has they get their team.
His script will run the for loop for the same player, it just doesn't do anything.
This will make some players not receive a team. |
|
|
| Report Abuse |
|
|
Cawlonee
|
  |
| Joined: 03 Mar 2014 |
| Total Posts: 2687 |
|
|
| 13 Mar 2014 11:05 AM |
players,team1,team2 = game.Players:GetChildren(),{},{}
t1num = math.ceil(#players/3)
for i=1,t1num do table.insert(team1,players[i]) end
for i=t1num+1,#players do table.insert(team2,players[i] end
for i,v in pairs(team1)do v.TeamColor = BrickColor.new("Color") end
for i,v in pairs(team2)do v.TeamColor = BrickColor.new("Color") end |
|
|
| Report Abuse |
|
|
|
| 13 Mar 2014 11:07 AM |
| Cal, you complicate things... |
|
|
| Report Abuse |
|
|
Cawlonee
|
  |
| Joined: 03 Mar 2014 |
| Total Posts: 2687 |
|
|
| 13 Mar 2014 11:10 AM |
I break my code up so anyone can understand.
He can condense it if he likes, at least it works. |
|
|
| Report Abuse |
|
|
Cawlonee
|
  |
| Joined: 03 Mar 2014 |
| Total Posts: 2687 |
|
|
| 13 Mar 2014 11:11 AM |
--Here, I'll condense it a little.
players,team1,team2 = game.Players:GetChildren(),{},{}
t1num = math.ceil(#players/3)
for i=1,#players do if i <= t1num then table.insert(team1,players[i]) else table.insert(team2,players[i]) end
for i,v in pairs(team1)do v.TeamColor = BrickColor.new("Color") end
for i,v in pairs(team2)do v.TeamColor = BrickColor.new("Color") end |
|
|
| Report Abuse |
|
|