Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- queueInitialize
- --place this in ServertScriptService
- _G.queueSize = 0
- local initializing = false
- local minimumPlayers = 1
- local function assignRed()
- local nextIndex = math.random(1,_G.queueSize)
- print("Index " .. tostring(nextIndex))
- local nextPlayer = _G.list[nextIndex]
- print(tostring(nextPlayer) .. " assigned to Red")
- nextPlayer.TeamColor = BrickColor.new("Really red")
- nextPlayer.queued:Destroy()
- -- Teleporting to red base will go here
- table.remove(_G.list,nextIndex)
- _G.queueSize = _G.queueSize -1
- end
- local function assignBlue()
- local nextIndex = math.random(1,_G.queueSize)
- print("Index " .. tostring(nextIndex))
- local nextPlayer = _G.list[nextIndex]
- print(tostring(nextPlayer) .. " assigned to Red")
- nextPlayer.TeamColor = BrickColor.new("Really blue")
- nextPlayer.queued:Destroy()
- -- Teleporting to blue base will go here
- table.remove(_G.list,nextIndex)
- _G.queueSize = _G.queueSize -1
- end
- local function initializeGame()
- print(initializing,_G.queueSize)
- if initializing then
- print("Already starting!")
- elseif (_G.queueSize >= minimumPlayers) then
- initializing = true
- print("Match now starting") print("Debug: Latejoin period will only be 10 seconds and only 1 player is needed.")
- wait(10)
- while _G.queueSize > 0 do -- Assigning remaining players
- assignRed()
- if _G.queueSize > 0 then
- assignBlue()
- if _G.queueSize == 1 then
- local extraPlayer = math.random(0,1)
- if extraPlayer == 0 then
- assignRed()
- else
- assignBlue()
- end -- Choose odd-one-out team
- end -- Assign odd-one-out to a team
- end -- Assign red then blue then random if there's exactly one left over
- initializing = false
- end --While Q>0 assign remaining players
- else --if Q > minimumPlayers then assign all players
- wait(1)
- 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.)")
- end
- end -- initializeGame()
- game.Workspace.queueButton.ClickDetector.MouseClick:Connect(initializeGame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement