local v for Y,y in pairs(BonusRoundFrame.BuyMode:GetChildren())do y.Buy.MouseButton1Click:connect(function()game.ReplicatedStorage.BuyMode:FireServer(y.Name,v)end)end game.ReplicatedStorage.BuyMode.OnClientEvent:connect(function(v,Y)local y=BonusRoundFrame.Title.Container.ModeContainer["\077\111\100\101"..v]y.Icon.Image=Icons[Y]or""y.ModeName.Text=""y.QMark.Visible=false local w=BonusRoundFrame.Title.Container.OverheadContainer["\077\111\100\101"..v]w.Buy.Visible=false w.Purchased.Visible=true end)local function Y(Y,y,w,I)BonusRoundFrame.Title.Container.ModeContainer:ClearAllChildren()BonusRoundFrame.Title.Container.OverheadContainer:ClearAllChildren()for Y,y in pairs(Y)do local w=script.GameMode:Clone()w.QMark.Visible=y=="\076\111\099\107\101\100"or y=="\082\097\110\100\111\109"w.ModeName.Text=(y=="\076\111\099\107\101\100"or y=="\082\097\110\100\111\109")and"\082\097\110\100\111\109"or""w.Locked.Visible=y=="\076\111\099\107\101\100"w.Icon.Image=Icons[y]or""if Y==1 then w.BackgroundColor3=Color3.new(.15686274509804,.15686274509804,.15686274509804)w.BorderColor3=Color3.new(.098039215686275,.098039215686275,.098039215686275)w.ModeName.TextColor3=Color3.new(.23137254901961,.23137254901961,.23137254901961)w.QMark.TextColor3=Color3.new(.23137254901961,.23137254901961,.23137254901961)w.Icon.Image=BWIcons[y]or""end w.Position=UDim2.new(0,(Y-1)*83,0,4)w.Name="\077\111\100\101"..Y w.Parent=BonusRoundFrame.Title.Container.ModeContainer local I=script.Overhead:Clone()local n=Y==2 local z=y=="\082\097\110\100\111\109"local m=y~="\082\097\110\100\111\109"and y~="\076\111\099\107\101\100"local E=z and not n I.Name="\077\111\100\101"..Y I.Buy.Visible=E if E then I.Buy.MouseButton1Click:connect(function()if v~=Y then BonusRoundFrame.BuyMode.Visible=true BonusRoundFrame.Loading.Visible=false BonusRoundFrame.Voting.Visible=false BonusRoundFrame.Nothing.Visible=false v=Y for v,Y in pairs(BonusRoundFrame.Title.Container.OverheadContainer:GetChildren())do Y.Buy.Style=Y==I and Enum.ButtonStyle.RobloxRoundButton or Enum.ButtonStyle.RobloxRoundDefaultButton end else v=nil I.Buy.Style=Enum.ButtonStyle.RobloxRoundDefaultButton BonusRoundFrame.BuyMode.Visible=false BonusRoundFrame.Loading.Visible=Stage=="\076\111\097\100\105\110\103"BonusRoundFrame.Voting.Visible=Stage=="\086\111\116\105\110\103"BonusRoundFrame.Nothing.Visible=Stage=="\078\111\116\104\105\110\103"end end)end I.Locked.Visible=y=="\076\111\099\107\101\100"and not n I.Next.Visible=n I.Purchased.Visible=m and not n I.Position=UDim2.new(0,(Y-1)*83,0,-2)I.Parent=BonusRoundFrame.Title.Container.OverheadContainer end if I then BonusRoundFrame.Nothing.Visible=false if w then RandomModes=w BonusRoundFrame.Voting.Visible=true Stage="\086\111\116\105\110\103"else RandomModes={}BonusRoundFrame.Voting.Visible=false BonusRoundFrame.Loading.Visible=true Stage="\076\111\097\100\105\110\103"BonusRoundFrame.Loading[y].Visible=true end UpdateVotes()end end game.ReplicatedStorage.VoteBonusRound.OnClientEvent:connect(function(v,y,w)Y(v,y,w,true)BonusRoundFrame.Visible=true end)local y=game.ReplicatedStorage.GetQueue:InvokeServer()Y(y)
--[[
GameGUI.Settings.Queue.MouseButton1Click:connect(function()
	BonusRoundFrame.Visible = not BonusRoundFrame.Visible;
end)]]

local BuyingIndex
for _, Frame in pairs(BonusRoundFrame.BuyMode:GetChildren()) do
	Frame.Buy.MouseButton1Click:connect(function()
		game.ReplicatedStorage.BuyMode:FireServer(Frame.Name, BuyingIndex)
	end)
end

game.ReplicatedStorage.BuyMode.OnClientEvent:connect(function(Index, GameMode)
	local ModeFrame = BonusRoundFrame.Title.Container.ModeContainer["Mode" .. Index]
	ModeFrame.Icon.Image = Icons[GameMode] or ""
	ModeFrame.ModeName.Text = ""
	ModeFrame.QMark.Visible = false
	local Overhead = BonusRoundFrame.Title.Container.OverheadContainer["Mode" .. Index]
	Overhead.Buy.Visible = false
	Overhead.Purchased.Visible = true
end)

local function UpdateQueue(BonusRoundQueue, CurrentMode, RandomM, StartVoting)
	BonusRoundFrame.Title.Container.ModeContainer:ClearAllChildren()
	BonusRoundFrame.Title.Container.OverheadContainer:ClearAllChildren()
	for Index, GameModeName in pairs(BonusRoundQueue) do
		local ModeFrame = script.GameMode:Clone()
		ModeFrame.QMark.Visible = (GameModeName == "Locked" or GameModeName == "Random")
		ModeFrame.ModeName.Text = (GameModeName == "Locked" or GameModeName == "Random") and "Random" or ""
		ModeFrame.Locked.Visible = (GameModeName == "Locked")
		ModeFrame.Icon.Image = Icons[GameModeName] or ""
		if Index == 1 then
			ModeFrame.BackgroundColor3 = Color3.new(40 / 255, 40 / 255, 40 / 255)
			ModeFrame.BorderColor3 = Color3.new(25 / 255, 25 / 255, 25 / 255)
			ModeFrame.ModeName.TextColor3 = Color3.new(59 / 255, 59 / 255, 59 / 255)
			ModeFrame.QMark.TextColor3 = Color3.new(59 / 255, 59 / 255, 59 / 255)
			ModeFrame.Icon.Image = BWIcons[GameModeName] or ""
		end
		ModeFrame.Position = UDim2.new(0, (Index - 1) * (76 + 7), 0, 4)
		ModeFrame.Name = "Mode" .. Index
		ModeFrame.Parent = BonusRoundFrame.Title.Container.ModeContainer

		local OverheadFrame = script.Overhead:Clone()
		local NextUp = (Index == 2)
		local Buy = (GameModeName == "Random")
		local Purchased = (GameModeName ~= "Random" and GameModeName ~= "Locked")
		local Buyable = (Buy and not NextUp)
		OverheadFrame.Name = "Mode" .. Index

		OverheadFrame.Buy.Visible = Buyable
		if Buyable then
			OverheadFrame.Buy.MouseButton1Click:connect(function()
				if BuyingIndex ~= Index then
					BonusRoundFrame.BuyMode.Visible = true
					BonusRoundFrame.Loading.Visible = false
					BonusRoundFrame.Voting.Visible = false
					BonusRoundFrame.Nothing.Visible = false
					BuyingIndex = Index

					for _, OV in pairs(BonusRoundFrame.Title.Container.OverheadContainer:GetChildren()) do
						OV.Buy.Style = (OV == OverheadFrame and Enum.ButtonStyle.RobloxRoundButton)
							or Enum.ButtonStyle.RobloxRoundDefaultButton
					end
				else
					BuyingIndex = nil
					OverheadFrame.Buy.Style = Enum.ButtonStyle.RobloxRoundDefaultButton
					BonusRoundFrame.BuyMode.Visible = false
					BonusRoundFrame.Loading.Visible = Stage == "Loading"
					BonusRoundFrame.Voting.Visible = Stage == "Voting"
					BonusRoundFrame.Nothing.Visible = Stage == "Nothing"
				end
				-- game.ReplicatedStorage.BuyMode:FireServer(Index);
			end)
		end

		OverheadFrame.Locked.Visible = (GameModeName == "Locked" and not NextUp)
		OverheadFrame.Next.Visible = NextUp
		OverheadFrame.Purchased.Visible = Purchased and not NextUp
		OverheadFrame.Position = UDim2.new(0, (Index - 1) * (76 + 7), 0, -2)
		OverheadFrame.Parent = BonusRoundFrame.Title.Container.OverheadContainer
	end

	if StartVoting then
		BonusRoundFrame.Nothing.Visible = false
		if RandomM then
			RandomModes = RandomM
			BonusRoundFrame.Voting.Visible = true
			Stage = "Voting"
		else
			RandomModes = {}
			BonusRoundFrame.Voting.Visible = false
			BonusRoundFrame.Loading.Visible = true
			Stage = "Loading"
			BonusRoundFrame.Loading[CurrentMode].Visible = true
		end
		UpdateVotes()
	end
end

game.ReplicatedStorage.VoteBonusRound.OnClientEvent:connect(function(BonusRoundQueue, CurrentMode, RandomM)
	UpdateQueue(BonusRoundQueue, CurrentMode, RandomM, true)
	BonusRoundFrame.Visible = true
end)

local BonusRoundQueue = game.ReplicatedStorage.GetQueue:InvokeServer()
UpdateQueue(BonusRoundQueue)
