Intermission and map voting system occasionally breaking

I’m currently experiencing an error with my minigames script
and the issue seems to be that whenever multiple people join at the same time or occasionally when 1 person joins, the map voting breaks the intermission timer breaks and it just displays this
image

  1. What solutions have you tried so far? I tried to add checks and redo the maps variable if no maps left

this is my code:

local players = {}
local voted = {}
Intermission = false
game.Players.PlayerAdded:Connect(function(plr)
	local map = workspace.Map:GetChildren()
	if map[1] then
		plr.Team = game.Teams.Game
	else
		plr.Team = game.Teams.Lobby
	end
	table.insert(players,plr)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local i = table.find(players,plr)
	if i then
		players[i] = nil
	end
end)

function Intermission2()
	workspace.Voting.Folder.Votes1.Value = 0
	workspace.Voting.Folder.Votes2.Value = 0
	workspace.Voting.Folder.Votes3.Value = 0
	voted = {}
	local maps = {}
	local Maps = game.ServerStorage.Maps:GetChildren()
	repeat task.wait()
		local rng1 = math.random(1,#Maps)
		if not table.find(maps,Maps[rng1].Name) then
			Map = Maps[rng1].Name
			table.insert(maps,Map)
			table.remove(Maps, table.find(Maps, Map))
			if not Maps[1] then
				Maps = game.ServerStorage.Maps:GetChildren()
			end
			print(maps)
		end
	until #maps >= 3
	--[[local rng2 = math.random(1,#Maps)
	if not table.find(maps,Maps[rng2].Name) then
		Map2 = Maps[rng2].Name
		table.insert(maps,Map2)
	end
	local rng3 = math.random(1,#Maps)
	if not table.find(maps,Maps[rng3].Name) then
		Map3 = Maps[rng3].Name
		table.insert(maps,Map3)
	end
	--]]
	workspace.Voting.Maps.Votes1:FindFirstChildOfClass("Folder").Name = maps[1]
	workspace.Voting.Maps.Votes2:FindFirstChildOfClass("Folder").Name = maps[2]
	workspace.Voting.Maps.Votes3:FindFirstChildOfClass("Folder").Name = maps[3]
	workspace.Intermission.Value = 30
	Intermission = true
	while Intermission == true do
		task.wait(1)
		if workspace.Intermission.Value <= 0 then
			Intermission = false
			break
		end
		workspace.Intermission.Value -= 1
		for _, v in pairs(game.Players:GetChildren()) do
			if v.PlayerGui:FindFirstChild("Timer") then
				v.PlayerGui.Timer.TextLabel.Text = "INTERMISSION: "..workspace.Intermission.Value
			end
		end
	end
	Start()
end

function Start()
	if players[2] then
		
	else
	   for _, v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.Timer.TextLabel.Text = "FAILED NOT ENOUGH PLAYERS"
		end
		task.wait(1)
		Intermission2()
		return
	end
	for _, v in pairs(game.Players:GetChildren()) do
		v.Team = game.Teams.Game
	end
	game.Teams.Game.AutoAssignable = true
	game.Teams.Lobby.AutoAssignable = false
	if workspace:FindFirstChild("Baseplate") then
		workspace.Baseplate.Parent = game.ReplicatedStorage
	end
	local values = {}
    local NumberValues = workspace.Voting.Folder

	for _,v in pairs(NumberValues:GetChildren()) do
		values[#values + 1] = {Obj = v; Value = v.Value}
	end

	table.sort(values, function(a, b)
		return a.Value > b.Value
	end)

	local highestValuePair = values[1]
	local highestObject = highestValuePair.Obj
	local highestValue = highestValuePair.Value

	local chosenMap = nil
	for _, v in pairs(highestObject.Parent.Parent.Maps[highestObject.Name]:GetChildren()) do
		if v:IsA("Folder") and v.Name ~= "Votes1" and v.Name ~= "Votes2" and v.Name ~= "Votes3" then
			if game.ServerStorage.Maps:FindFirstChild(v.Name) then
				chosenMap = v.Name
			end
		end
	end
	print(chosenMap)
	if chosenMap ~= nil then
	local Map = game.ServerStorage.Maps:FindFirstChild(chosenMap)
	if Map then
		for _, v in pairs(game.Players:GetChildren()) do
			v.PlayerGui.Timer.TextLabel.Text = "MAP CHOSEN: "..chosenMap
		end
		task.wait(1)
		for _,v in pairs(workspace.Players:GetChildren()) do
				v.Humanoid.Health = 0
		end
		local G = Map:Clone()
		G.Parent = workspace.Map
		game.Debris:AddItem(G,350)
		workspace.TimeRemaining.Value = 300
		local c = coroutine.create(function()
			while task.wait(1) do
					workspace.TimeRemaining.Value -= 1
					if workspace.TimeRemaining.Value <= 0 then
						break
					end
				end
				EndGame()
		end)
			coroutine.resume(c)
	end
	else
		EndGame()
	end
end

function EndGame()
	workspace.Intermission.Value = 30
	if workspace.Map:FindFirstChildOfClass("Model") then
		local map = workspace.Map:FindFirstChildOfClass("Model")
		map:Destroy()
	end
	local killCount = {}

	for _,v in pairs(game.Players:GetChildren()) do
		table.insert(killCount,v)
		v.Character.LastHit.Value = ""
		v.Character.Humanoid.Health = 0
		v.Team = game.Teams.Lobby
	end
	table.sort(killCount, function(a, b)
		return a.leaderstats.Kills.Value > b.leaderstats.Kills.Value
	end)
	local first, second, third = killCount[1], killCount[2], killCount[3]
	if first then
		first.leaderstats.Cash.Value += 150
		local child = first.Quests:FindFirstChild("Win 5 minigames")
		if child then
			child.Progress.Value += 1
		end
	end
	if second then
		second.leaderstats.Cash.Value += 100
	end
	if third then
		third.leaderstats.Cash.Value += 50
	end
	if second == nil then
		second = "NO ONE"
	end
	if third == nil then
		third = "NO ONE"
	end
	game.Teams.Game.AutoAssignable = false
	game.Teams.Lobby.AutoAssignable = true
	if game.ReplicatedStorage:FindFirstChild("Baseplate") then
		game.ReplicatedStorage.Baseplate.Parent = workspace
	end
	for _,v in pairs(game.Players:GetChildren()) do
		v.leaderstats.Kills.Value = 0
	end
	task.wait(5)
	for _,v in pairs(game.Players:GetChildren()) do
		v.leaderstats.Kills.Value = 0
	end
	for _,v in pairs(game.Players:GetChildren()) do
		if first and second and third ~= "NO ONE" then
		v.PlayerGui.Timer.TextLabel.Text = "WINNERS: "..first.Name.." : 150 cash, "..second.Name.." : 100 cash, "..third.Name..": 50 cash"
		else
			if second and third == "NO ONE" then
				v.PlayerGui.Timer.TextLabel.Text = "WINNERS: "..first.Name.." : 150 cash, "..second.." : 100 cash, "..third..": 50 cash"
				end
		end	
	end
	Intermission2()
end

function Intermission()
	workspace.Voting.Folder.Votes1.Value = 0
	workspace.Voting.Folder.Votes2.Value = 0
	workspace.Voting.Folder.Votes3.Value = 0
	voted = {}
	local maps = {}
	local Maps = game.ServerStorage.Maps:GetChildren()
	repeat task.wait()
	local rng1 = math.random(1,#Maps)
	if not table.find(maps,Maps[rng1].Name) then
		Map = Maps[rng1].Name
			table.insert(maps,Map)
			table.remove(Maps, table.find(Maps, Map))
			if not Maps[1] then
				Maps = game.ServerStorage.Maps:GetChildren()
			end
		end
		until #maps >= 3
	--[[local rng2 = math.random(1,#Maps)
	if not table.find(maps,Maps[rng2].Name) then
		Map2 = Maps[rng2].Name
		table.insert(maps,Map2)
	end
	local rng3 = math.random(1,#Maps)
	if not table.find(maps,Maps[rng3].Name) then
		Map3 = Maps[rng3].Name
		table.insert(maps,Map3)
	end
	--]]
	workspace.Voting.Maps.Votes1:FindFirstChildOfClass("Folder").Name = maps[1]
	workspace.Voting.Maps.Votes2:FindFirstChildOfClass("Folder").Name = maps[2]
	workspace.Voting.Maps.Votes3:FindFirstChildOfClass("Folder").Name = maps[3]
	workspace.Intermission.Value = 30
	Intermission = true
	while Intermission == true do
		task.wait(1)
		if workspace.Intermission.Value <= 0 then
			Intermission = false
			break
		end
		workspace.Intermission.Value -= 1
		for _, v in pairs(game.Players:GetChildren()) do
			if v.PlayerGui:FindFirstChild("Timer") then
			v.PlayerGui.Timer.TextLabel.Text = "INTERMISSION: "..workspace.Intermission.Value
			end
		end
	end
	Start()
end

workspace.Voting.Vote1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not table.find(voted,plr.Name) then
				table.insert(voted,plr.Name)
				workspace.Voting.Folder.Votes1.Value += 1
			end
		end
	end
end)

workspace.Voting.Vote2.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not table.find(voted,plr.Name) then
				table.insert(voted,plr.Name)
				workspace.Voting.Folder.Votes2.Value += 1
			end
		end
	end
end)

workspace.Voting.Vote3.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr then
			if not table.find(voted,plr.Name) then
				table.insert(voted,plr.Name)
				workspace.Voting.Folder.Votes3.Value += 1
			end
		end
	end
end)
Intermission()

Any ideas how to fix this?