Advertisement
Pandarsenic

Roblox Script -- Queue Part 2

Jul 13th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.09 KB | None | 0 0
  1. queueInitialize
  2.  
  3. --place this in ServertScriptService
  4.  
  5. _G.queueSize = 0
  6. local initializing = false
  7.  
  8. local minimumPlayers = 1
  9.  
  10. local function assignRed()
  11.     local nextIndex = math.random(1,_G.queueSize)
  12.     print("Index " .. tostring(nextIndex))
  13.     local nextPlayer = _G.list[nextIndex]
  14.     print(tostring(nextPlayer) .. " assigned to Red")
  15.     nextPlayer.TeamColor = BrickColor.new("Really red")
  16.     nextPlayer.queued:Destroy()
  17.     -- Teleporting to red base will go here
  18.     table.remove(_G.list,nextIndex)
  19.     _G.queueSize = _G.queueSize -1
  20. end
  21.  
  22. local function assignBlue()
  23.     local nextIndex = math.random(1,_G.queueSize)
  24.     print("Index " .. tostring(nextIndex))
  25.     local nextPlayer = _G.list[nextIndex]
  26.     print(tostring(nextPlayer) .. " assigned to Red")
  27.     nextPlayer.TeamColor = BrickColor.new("Really blue")
  28.     nextPlayer.queued:Destroy()
  29.     -- Teleporting to blue base will go here
  30.     table.remove(_G.list,nextIndex)
  31.     _G.queueSize = _G.queueSize -1
  32. end
  33.  
  34. local function initializeGame()
  35.     print(initializing,_G.queueSize)
  36.     if initializing then
  37.         print("Already starting!")
  38.     elseif (_G.queueSize >= minimumPlayers) then
  39.         initializing = true
  40.         print("Match now starting") print("Debug: Latejoin period will only be 10 seconds and only 1 player is needed.")
  41.         wait(10)
  42.             while _G.queueSize > 0 do -- Assigning remaining players
  43.                 assignRed()
  44.             if _G.queueSize > 0 then
  45.                 assignBlue()
  46.             if _G.queueSize == 1 then
  47.                 local extraPlayer = math.random(0,1)
  48.                 if extraPlayer == 0 then
  49.                     assignRed()
  50.                 else
  51.                     assignBlue()
  52.                 end -- Choose odd-one-out team
  53.             end -- Assign odd-one-out to a team
  54.             end -- Assign red then blue then random if there's exactly one left over
  55.         initializing = false
  56.         end --While Q>0 assign remaining players
  57.     else --if Q > minimumPlayers then assign all players
  58.         wait(1)
  59.         print("Could not start. Currently " .. _G.queueSize .. " players out of " .. minimumPlayers .. " required. (If you are at the exact number of players needed, use the block again to start.)")
  60.     end
  61. end -- initializeGame()
  62.  
  63. game.Workspace.queueButton.ClickDetector.MouseClick:Connect(initializeGame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement