Map voting system

I currently have a round system where the players spawn in a lobby and then get teleported to a map after an intermission. I now want to move on to having a GUI voting system with multiple maps where the players can vote on what map they want to play. I want to attempt to follow HowToRoblox’s video on their voting system (https://www.youtube.com/watch?v=Nx-2jr6TQmk&t=205s) by moving the maps into replicated storage and then calling them, but unsure if there is a better way to go about this. Any suggestions would be greatly appreciated!

Main Script:

local intermission = 10
local roundLength = 15

local inRound = game.ReplicatedStorage.InRound
local status = game.ReplicatedStorage.Status

local playingTeam = game.Teams.Playing
local lobbyTeam = game.Teams.Lobby

local ServerStorage = game:GetService("ServerStorage")
local BasicSword = ServerStorage["Basic Sword"]

local firstMap = game.Workspace.FirstMap
-- local secondMap = game.Workspace.SecondMap
-- local thirdMap = game.Workspace.ThirdMap

-- local Maps = {firstMap, secondMap, thirdMap}

inRound.Changed:Connect(function ()
	
	if inRound.Value == true then
		
		for i, plr in pairs(game.Players:GetChildren()) do
			
			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")
			
			local CloneBasic = BasicSword:Clone()
			CloneBasic.Parent = plr.Backpack
			
			local spawns = firstMap:FindFirstChild("Spawns")
			local points = spawns:GetChildren()
			
			plr.Character:WaitForChild("HumanoidRootPart").CFrame = points[i].CFrame --This
			
			table.remove(points,1)
			
			plr.Team = playingTeam
			
			char:WaitForChild("Humanoid").Died:Connect(function()
				
				plr.Team = lobbyTeam
				
				
			end)

			
		end
		
	else
		
		for i, plr in pairs(game.Players:GetChildren()) do

			for i, plr in game.Players:GetPlayers() do
				if plr.Team == lobbyTeam then
					continue
				end

				plr.Team = lobbyTeam
				plr.Backpack:ClearAllChildren()

				local char = plr.Character
				
				local humanRoot = char and char:FindFirstChild("HumanoidRootPart")

				for i, child in ipairs(char:GetChildren()) do
					if child:IsA("Tool") then
						child:Destroy()
					end
				end
				
				if humanRoot then
					humanRoot.CFrame = workspace.Lobby.lobbySpawn.CFrame
				end
			end	
			
		end
	end 
end)




local function round()
	
	while true do
		
		local requiredPlayers = 1
		
		repeat
			wait(1)
			status.Value = "Atleast ".. requiredPlayers.." players are needed to start a round"
			
		until #game.Players:GetChildren() >= requiredPlayers
		
		inRound.Value = false
		
		
		
		for i = intermission, 0, -1 do
			
			status.Value = "Game will start in "..i.." seconds"
			
			wait(1)
		end
		
		inRound.Value = true
		
		
		
		for i = roundLength, 0, -1 do

			status.Value = "Game will end in "..i.." seconds"
			
			local playing = {}
			
			for i, plr in pairs(game.Players:GetChildren()) do
				
				if plr.Team.Name == "Playing" then
					
					
					table.insert(playing, plr.Name)
					
				end
			end
			
			if #playing == 2 then
				
				status.Value = "SHOWDOWN"
				
				roundLength = 1
				
			end
			
			
			if #playing == 0 then
				
				status.Value = "Everyone has died."
				
				wait(3)
				break

			end
			
			
			if #playing == 1 then
				
				status.Value = playing[1].." Has Won The Game!"

				for i, plr in pairs(game.Players:GetChildren()) do
					if playing[1] == plr.name then
						plr.leaderstats.Wins.Value += 1
					end
				end
				
				wait(1)
				break
				
			
		end	
		
			wait(1)		
			
		end
		wait(3)
		
		
	end
end

spawn(round)
1 Like

Hey!

Looking at your comments, I’m not sure if there is a more optimized way, but from what I understand it’s the best you can do for now! Don’t overload the script too much, what I do recommend is that when a map is taken from a storage to the workspace, have a loading time in which the map finishes loading completely, this to avoid lags, bugs and among other things. I hope you do well in your work!

1 Like