Round system tiebreaker not working correctly

i want a tiebreaker for my game but when i tried to reset the map so that its back to its default, it chooses another map and sorta breaks it. i know that the issue is with the fact that im choosing another random map but i dont know how to retrieve the map that was already chosen.

ServerStorage = game:GetService("ServerStorage")
ReplicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
teams = game:GetService("Teams")
DataStoreService = game:GetService("DataStoreService")
CashDataStore = DataStoreService:GetDataStore("cashDataStore")

Maps = ServerStorage:WaitForChild('Maps'):GetChildren()
RoundStatus = ReplicatedStorage:WaitForChild('RoundStatus')

local Survivors = {}


while wait() do
	if #game.Players:GetPlayers() >= 2 then

		local countdown = 3
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Intermission: "..i
			wait(1)
		end

		ChosenMap = Maps[math.random(1, #Maps)]:Clone()
		Spawns = ChosenMap:FindFirstChild('Spawns'):GetChildren()

		RoundStatus.Value = ChosenMap.Name.." has been chosen!"

		wait(5)

		countdown = 1
		for i = countdown, 0, -1 do
			ChosenMap.Parent = workspace
			RoundStatus.Value = "Teleporting everyone..."

			local Players = game.Players:GetPlayers()

			for _, Player in ipairs(game.Players:GetPlayers())do
				if Player.Character and Player.Character:WaitForChild('Humanoid') then
					RandomSpawn = Spawns[math.random(1, #Spawns)]
					Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
					Player.TeamColor = BrickColor.new("Persimmon")
					Player.Character.Humanoid.MaxHealth = 100
					Player.Character.Humanoid.Health = 100
					Player.Character.Humanoid.WalkSpeed = 16
					Survivors[Player] = true
				end
			end

			wait(1)
		end

		countdown = 999999999999999999999999999999999999999999999999999999999999999999
		for i = countdown, 0, -1 do
			RoundStatus.Value = "Game is currently in progress.."

			local Survivor = game.Teams.Playing
			if #Survivor:GetPlayers() == 1 then
				for i,v in pairs(game.Teams["Playing"]:GetPlayers()) do
					v.leaderstats.Cash.Value += 1

					for _, Player in pairs(game.Players:GetChildren())do
						if Player.Character and Player.Character:FindFirstChild('Humanoid') then
							Player.Character.Humanoid.Health = 0
						end
					end

					countdown = 3
					for i = countdown, 0, -1 do
						ChosenMap:Destroy()
						RoundStatus.Value = "Round Over!"
						local winner = game.ReplicatedStorage.Winner
						winner.Value = v.Name
						wait(1)
					end

					countdown = 5
					for i = countdown, 0, -1 do
						ChosenMap:Destroy()
						RoundStatus.Value = v.Name.. " has won!"
						local winner = game.ReplicatedStorage.Winner
						winner.Value = v.Name
						wait(1)
					end

				end
				break
			end
			
			while countdown > 0 and #Survivor:GetPlayers() == 0 do
				ChosenMap:Destroy()
				ChosenMap = Maps[math.random(1, #Maps)]:Clone()
				ChosenMap.Parent = workspace
				
				
				for _, Player in ipairs(game.Players:GetPlayers())do
					if Player.Character and Player.Character:WaitForChild('Humanoid') then
						RandomSpawn = Spawns[math.random(1, #Spawns)]
						Player.Character.HumanoidRootPart.CFrame = RandomSpawn.CFrame
						Player.TeamColor = BrickColor.new("Persimmon")
						Player.Character.Humanoid.MaxHealth = 100
						Player.Character.Humanoid.Health = 100
						Player.Character.Humanoid.WalkSpeed = 16
						Survivors[Player] = true
					end
				end
			end

			wait(1)
		end

	else
		local dots = "..."

		repeat
			for i = 1,3 do
				RoundStatus.Value = "Waiting For Players"..string.sub(dots, 1, i)
				wait(1)
			end
		until #game.Players:GetPlayers() >= 2
	end

end

the issue lies in the while countdown > 0 and #Survivor:GetPlayers() == 0 do loop

If the Maps have different Names, you can get the already chosen Map by doing ChosenMap = Maps:FindFirstChild(ChosenMap.Name):Clone()

1 Like