rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
|
| 05 Jul 2015 03:38 PM |
Just the title, makening some war games and i dont know how to. Thanks! |
|
|
| Report Abuse |
|
|
rubene45
|
  |
| Joined: 08 May 2012 |
| Total Posts: 333 |
|
| |
|
mycheeze
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 6748 |
|
| |
|
|
| 05 Jul 2015 03:55 PM |
local table = require(199207348) local Teams = game:GetService("Teams") local Players = game.Players
function RandomizeTeams() local plrs = table.shuffle({unpack(Players:GetPlayers())}) local colors = table.results(Teams, function() return v.TeamColor end) for i = 1, #plrs do plrs.TeamColor = colors[(i%#colors)+1] end end
Try that and see what happens :) |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 04:01 PM |
"{unpack(Players:GetPlayers())}"
You're pulling everything out of a table... to put it back into a table?
It also would probably be better to sort the players by their rank or KDR or something, then swap the positions of players that are right next to each other so the teams end up pretty evenly matched but still random. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 04:05 PM |
@morash Last I checked the wiki said that GetChildren returns a read-only table, so I assumed so did GetPlayers, and since my table.shuffle modifies the table, I repacked it just in case.
Althought you could've done this instead (table.pack is part of my module LOL)
local plrs = table.shuffle(table.pack(table.unpack(Players:GetPlayers()))) |
|
|
| Report Abuse |
|
|
morash
|
  |
| Joined: 22 May 2010 |
| Total Posts: 5834 |
|
|
| 05 Jul 2015 04:10 PM |
It's not read-only. I just ran this through the command line:
t = workspace:GetChildren() t[1] = workspace
for i,v in pairs (t) do t[i] = v.Name end
print(unpack(t))
And the results were: Workspace Camera WalkBot |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 04:10 PM |
| Okay then, I'll rewrite my code then. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 04:11 PM |
local table = require(199207348) local Teams = game:GetService("Teams") local Players = game.Players
function RandomizeTeams() local plrs = table.shuffle(Players:GetPlayers()) local colors = table.results(Teams, function() return v.TeamColor end) for i = 1, #plrs do plrs.TeamColor = colors[(i%#colors)+1] end end |
|
|
| Report Abuse |
|
|
VuItured
|
  |
| Joined: 28 Jun 2015 |
| Total Posts: 52 |
|
|
| 05 Jul 2015 04:17 PM |
Do you want it balanced or just placed randomly? Like for example there are 6 players and you want 3 on each team or you just want it random :P
where my cookie |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 04:19 PM |
| Did my function work for you? |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2015 04:32 PM |
Woops I made a slight typo in my function, lol try this and tell me if it works:
local table = require(199207348) local Teams = game:GetService("Teams") local Players = game.Players
function RandomizeTeams() local plrs = table.shuffle(Players:GetPlayers()) local colors = table.results(Teams, function(v) return v.TeamColor end) for i = 1, #plrs do plrs.TeamColor = colors[(i%#colors)+1] end end |
|
|
| Report Abuse |
|
|