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 » Scripting Helpers
Home Search
 

Re: team randomizer

Previous Thread :: Next Thread 
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
09 Jun 2014 07:05 PM
How can I make this work if it doesn't already?

function team()
local p = game.Players:GetPlayers()
local r, b = 0, 0
for i = 1, #p do
local n = math.random(1, 2)
if n == 1 then
if r <= b then
p[i].TeamColor = red.TeamColor
r = r + 1
elseif r > b then
p[i].TeamColor = blue.TeamColor
b = b + 1
end
elseif n == 2 then
if b <= r then
p[i].TeamColor = blue.TeamColor
b = b + 1
elseif b > r then
p[i].TeamColor = red.TeamColor
r = r + 1
end
end
end
end
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
09 Jun 2014 07:05 PM
you didnt execute it...
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
09 Jun 2014 07:07 PM
i did, just not in this function
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jun 2014 07:07 PM
red and blue are nil. also this is a bit more complicated than it has to be.
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
09 Jun 2014 07:09 PM
forgot to mention everything is defined
Report Abuse
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
09 Jun 2014 07:10 PM
give us the whole script please
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
09 Jun 2014 07:12 PM
here is the script so far

local teams = game.Teams repeat wait(0) until teams
red, blue = teams.Red, teams.Blue
spectators = teams.Spectators

controller = game.ServerStorage:WaitForChild("Info Controller")
min = 1

function script(stringvalue, value)
for str = 1, value:len() do
stringvalue.Value = value:sub(1, str)
wait(0.05)
end
wait(2)
stringvalue.Value = ""
end

function check()
while true do wait()
if #game.Players:GetPlayers() < min then
script(controller, "Need at least " .. min .. " players to start.")
elseif #game.Players:GetPlayers() >= min then
script(controller, "Initializing game.")
break
end
end
announce(select())
end

function select()
m = {}
tab = game.ServerStorage:GetChildren()
for obj = 1, #tab do
if tab[obj]:IsA("Model") then
m[#m + 1] = tab[obj]
end
end
local selected = m[math.random(#m)]
return selected
end

function announce(map)
script(controller, map.Name .. " has been chosen.")
script(controller, "Waiting for scripts.")
end

function run(map)
team()
map:Clone().Parent = Workspace
-- to do
end

function team()
local p = game.Players:GetPlayers()
local r, b = 0, 0
for i = 1, #p do
local n = math.random(1, 2)
if n == 1 then
if r <= b then
p[i].TeamColor = red.TeamColor
r = r + 1
elseif r > b then
p[i].TeamColor = blue.TeamColor
b = b + 1
end
elseif n == 2 then
if b <= r then
p[i].TeamColor = blue.TeamColor
b = b + 1
elseif b > r then
p[i].TeamColor = red.TeamColor
r = r + 1
end
end
end
end

function lobby(time)
for i = time, 0, -1 do
wait(1)
controller.Value = "Time until next round: " .. i .. " seconds."
end
check()
end

lobby(5)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jun 2014 07:26 PM
'local teams = game.Teams repeat wait(0) until teams'
?

If somehow, magically, Teams is nil at that time, that repeat statement will wait forever (whether it was created or not) so that repeat loop is useless. Anyways, is there an output?
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jun 2014 07:28 PM
local teams = {red = game.Teams.Red, blue = game.Teams.Blue}
local switch = true
for i,v in pairs(game.Players:GetPlayers()) do
v.TeamColor = (switch and teams.red.TeamColor or teams.blue.TeamColor)
switch = not switch
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jun 2014 07:31 PM
Azarth, that's not randomized.
Do something like:

local teams = {red = game.Teams.Red.TeamColor, blue = game.Teams.Blue.TeamColor};
local randomizeTeams = function()
local players = Game.Players:GetPlayers();
for key = 1, #players do
local randomPlayer = table.remove(players, math.random(#players));
if key <= math.ceil(#players / 2) do
randomPlayer.TeamColor = teams.red;
else
randomPlayer.TeamColor = teams.nblue;
end
end
end;
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jun 2014 07:33 PM
I read equalize.
Report Abuse
Azarth is not online. Azarth
Joined: 17 Aug 2012
Total Posts: 2760
09 Jun 2014 07:33 PM
I'm blind.
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
09 Jun 2014 08:54 PM
local teams = game:GetService("Teams")

would that be a better replacement?

Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Jun 2014 09:00 PM
If the name of teams somehow gets changed, then yes.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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