|
| 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 |
|
|
| |
|
|
| 09 Jun 2014 07:07 PM |
| i did, just not in this function |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 09 Jun 2014 07:09 PM |
| forgot to mention everything is defined |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2014 07:10 PM |
| give us the whole script please |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
| |
|
Azarth
|
  |
| Joined: 17 Aug 2012 |
| Total Posts: 2760 |
|
| |
|
|
| 09 Jun 2014 08:54 PM |
local teams = game:GetService("Teams")
would that be a better replacement?
|
|
|
| Report Abuse |
|
|
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 |
|
|