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 » Scripters
Home Search
 

Re: How can i chosse random people for teams?

Previous Thread :: Next Thread 
rubene45 is not online. 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 is not online. rubene45
Joined: 08 May 2012
Total Posts: 333
05 Jul 2015 03:45 PM
Bump
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
05 Jul 2015 03:46 PM
How many teams are there
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
05 Jul 2015 04:10 PM
Okay then, I'll rewrite my code then.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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 is not online. 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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
05 Jul 2015 04:19 PM
Did my function work for you?
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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