Overly complicated Map rotation/TDM script breaks and I don't know why

So bassically, im making a game with some friends and Ive spent about a month trying to making a map rotation/round system, I accually got it to work but then I just decided to break on me for reasons I don’t know.

All that I really need to know here is why does it break, and what can I do to simplify this code? (keep in mind im a bit of a mediocre scripter)

Ive also provided a video if its helpful

local RS = game.ReplicatedStorage
local MPS = RS.Maps
local M1 = MPS.MAP4Square
local M2 = MPS.MAPPansCity
local M3 = MPS.MAPJunction

-- variable used for time and status messagess
local iv = 0
local s = script.Stat
local TM = script.Parent.TimeValue

local T1 = game.Teams["Blue Bombers"]
local T2 = game.Teams["Red Raiders"]
local Event1 = script.Parent.Gamestart

-- Intermission
while true do
	iv = 15
	repeat
		iv = iv-1
		s.Value = "Waiting For New round.. "..iv
		wait(1)
	until iv == 0
	s.Value = "New Match Starting!"
	wait(2)
	
-- RNG for map rotation
	local MapRNG = math.random(1,3)
		if MapRNG == 1 then do
			s.Value = "The Map Is 4Square!"
			workspace.CurrentMap:ClearAllChildren()
			local map = M1:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
		end
		elseif MapRNG == 2 then do
				s.Value = "Next Map will be PANS City!"
			workspace.CurrentMap:ClearAllChildren()
				local map = M2:Clone()
			map.Parent = workspace.CurrentMap
				s.Value = "Loading up map sit tight!"
				wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
			end
	elseif MapRNG == 3 then do
			s.Value = "Next Map will be Junction!"
			local map = M3:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
		end
	
-- Initiates a Team Deathmatch type of mode
-- for some reason this is skipped entirely and the intermission restarts 
			
TM.Value = 150 -- this is just how long the match will last
		print("Went through!") -- this is to tell me when TDM starts being read
			game:GetService('Players').PlayerAdded:Connect(function(player)
				player.CharacterAdded:Connect(function(character)
					character:WaitForChild("Humanoid").Died:Connect(function()
						print(game.Players[character.Name].TeamColor)
						if game.Players[character.Name].TeamColor == T1.TeamColor then do
								T2.Points.Value = T2.Points.Value + 20
							end
						elseif game.Players[character.Name].TeamColor == T2.TeamColor then do
								T1.Points.Value = T1.Points.Value + 20

							repeat -- timer counts down to 0 and the script loops itself
								TM.Value = TM.Value - 1
								wait(1)
							until TM.Value <= 0
							end
						end
					end)
				end)
			end)
				end
			end

This isn’t going to fix your script, but to make the map chooser cleaner, put all the maps in a folder, use :GetChildren() on that folder, and do something like this

local maps = folder:GetChildren()
--choose random number
map = maps[randomnumber]
s.Value = "Next Map will be ".. map.name.."!"
map = map:Clone()
map.Parent = workspace

I know that the map choosing system is a bit messy but thanks for the simplification ill be sure to try and implement

You should show the output menu. It shows errors that may occur in your script.

the output was completely clear, the print statement was never fired nor did i receive any errors and thats what bugs me image

You don’t have an extra end here, also I don’t get why you use do end in an if then statement.
The bottom part will only run if the RNG value is 3

alright let me try it out to see if it will work

alright so i tried removing the “then do” loops and set the rng value to 3 yet it still seems to work the same

-- RNG for map rotation
	local MapRNG = math.random(3,3)
		if MapRNG == 1 then
			s.Value = "The Map Is 4Square!"
			workspace.CurrentMap:ClearAllChildren()
			local map = M1:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
		elseif MapRNG == 2 then
				s.Value = "Next Map will be PANS City!"
			workspace.CurrentMap:ClearAllChildren()
				local map = M2:Clone()
			map.Parent = workspace.CurrentMap
				s.Value = "Loading up map sit tight!"
				wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
	elseif MapRNG == 3 then
			s.Value = "Next Map will be Junction!"
			local map = M3:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
		
TM.Value = 150 -- this is just how long the match will last
		print("Went through!") -- this is to tell me when TDM starts being read
			game:GetService('Players').PlayerAdded:Connect(function(player)
				player.CharacterAdded:Connect(function(character)
					character:WaitForChild("Humanoid").Died:Connect(function()
						print(game.Players[character.Name].TeamColor)
						if game.Players[character.Name].TeamColor == T1.TeamColor then
								T2.Points.Value = T2.Points.Value + 20
						elseif game.Players[character.Name].TeamColor == T2.TeamColor then
								T1.Points.Value = T1.Points.Value + 20
							repeat -- timer counts down to 0 and the script loops itself
								TM.Value = TM.Value - 1
								wait(1)
							until TM.Value <= 0
						end
					end)
				end)
			end)
				end
			end

You need an end after this, and remove an end from the very end

tried it didnt work aswell

elseif MapRNG == 3 then
			s.Value = "Next Map will be Junction!"
			local map = M3:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace.CurrentMap
end

Alright so its been like about like, two days or so and ive managed to fix the script by myself

probably most notable is that ive moved the kill registration to another script and instead of using “elseif” I have separated each of the maps into their own if statements along with the timer .

It might be a bit “messy” but I guess if it works, it works.

local RS = game.ReplicatedStorage
local MPS = RS.Maps
local s = script.Stat
local M1 = MPS.MAP4Square
local M2 = MPS.MAPPansCity
local M3 = MPS.MAPJunction
local t = 0

local T1 = game.Teams["Blue Bombers"]
local T2 = game.Teams["Red Raiders"]
local TM = script.Parent.TimeValue
local Event1 = script.Parent.Gamestart

local s = script.Stat
t = 0
while true do
	t = 15
	T1.Points.Value = 0
	T2.Points.Value = 0
	repeat
		t = t-1
		s.Value = "Intermission.. "..t
		wait(1)
	until t == 0
	s.Value = "Game starting!"
	wait(2)
	local MapRNG = math.random(1,3)
		if MapRNG == 1 then
			s.Value = "The Map Is 4Square!"
			wait(2)
			local map = M1:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace
		TM.Value = 10
		repeat
			TM.Value = TM.Value - 1
			wait(1)
		until TM.Value <= 0
		if TM.Value <= 0 then
			workspace.CurrentMap:ClearAllChildren()
			workspace.SpawnPoints:Destroy()
		end
	end
		if MapRNG == 2 then
				s.Value = "Next Map will be PANS CITY!"
				wait(2)
				local map = M2:Clone()
			map.Parent = workspace.CurrentMap
				s.Value = "Loading up map sit tight!"
				wait(5)
			map.SpawnPoints.Parent = workspace
		TM.Value = 10
		repeat
			TM.Value = TM.Value - 1
			wait(1)
		until TM.Value <= 0
		if TM.Value <= 0 then
			workspace.CurrentMap:ClearAllChildren()
			workspace.SpawnPoints:Destroy()
		end
	end
		if MapRNG == 3 then do
			s.Value = "Next Map will be Junction!"
			wait(2)
			local map = M3:Clone()
			map.Parent = workspace.CurrentMap
			s.Value = "Loading up map sit tight!"
			wait(5)
			map.SpawnPoints.Parent = workspace
			print("Went through!")
			TM.Value = 10
			repeat
				TM.Value = TM.Value - 1
				wait(1)
			until TM.Value <= 0
			if TM.Value <= 0 then
				workspace.CurrentMap:ClearAllChildren()
				workspace.SpawnPoints:Destroy()
				end
				end
			end
		end