How Would I fix my round system?

I’ve created a round system for my game, and I recently added a new feature that would stop the round if:

A.
The Time Ran Out

or

B.
All Players tagged ‘Alive’ (CollectionService) die before the time runs out.

Unfortunately, my attempt at implementing this clearly failed, a the intermission value stays at 0.

Code:

local  roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end
local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end
local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end
local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end
local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end
local roundtime = game.ReplicatedStorage.RoundTime
local inter =  game.ReplicatedStorage:WaitForChild("Intermission")
local collectionService = game:GetService("CollectionService")
local numberOfDisasters

inter.Value = 30
roundtime.Value = 120
function TagAllPlayers(Tag)
	for i, v in pairs(game.Players:GetPlayers())do
		collectionService:AddTag(v, Tag)
	end
end
function CleanUp()
	workspace["SpleefMap"]:Destroy()
	for i, v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Handle") then
			v:Destroy()
		end
	end
	delay(2, function()
		print("Regenerating")
		local Clone = game.ServerStorage:WaitForChild("SpleefMap"):Clone()
		local chosenColor = BrickColor.Random()
		for i, v in pairs(Clone:GetDescendants()) do
			if v:IsA("Part") then
				v.BrickColor = chosenColor
			end
		end
		local ss = game.ServerStorage.PartTagger:Clone()
		Clone.Parent = workspace
		ss.Parent = Clone
	end)
	
end
function AwardPlayers()
	local Winners = {}
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		table.insert(Winners, #Winners+1, v)
		collectionService:RemoveTag(v, "Alive")
	end

	for i, v in pairs(Winners) do
		local chosenAmount
		local function CheckPermission(plr)
			if plr:IsInGroup(7895196)then
				return true
			end

		end

		print(v.Name.." Was A Winner")
		if CheckPermission(v) then
			chosenAmount = 60
		else
			chosenAmount = 50
		end
		v:WaitForChild("SpleefCoins").Value += chosenAmount
		v:WaitForChild("leaderstats"):WaitForChild("Wins").Value += 1
		game.ServerStorage.DisasterEvent:Fire(0, false)

		game.ReplicatedStorage.ShowMoneyEffect:FireClient(v,chosenAmount)
	end
	game.ReplicatedStorage.showWinnersEvent:FireAllClients(Winners)
	game.ReplicatedStorage.IsIntermission.Value = true
end

function CheckPlayersTag(Tag)
	for i, v in pairs(collectionService:GetTagged("Alive")) do
		local Character = v.Character
		if Character then
			if Character:WaitForChild("Humanoid").Health == 0 then
				v:WaitForChild("CRW").Value = false
				collectionService:RemoveTag(v, "Alive")
				collectionService:AddTag(v, "Dead")
			end
		end
	end
end
function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

function TeleportPlayers()
	local Tiles = workspace["SpleefMap"]:GetDescendants()
	local ATiles= {}
	for i, v in pairs(Tiles) do
		if v:IsA("Part") then
			table.insert(ATiles, #ATiles+1, v)
		end
	end
	for index, Player in pairs(game:GetService("Players"):GetPlayers()) do
		local CanRecieveWeapons = Instance.new("BoolValue", Player)
		CanRecieveWeapons.Name = "CRW"
		CanRecieveWeapons.Value =true
		local TileChosen = ATiles[math.random(1, #ATiles)]
		local HRP = Player.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part" ) then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		end
	end
end

function CheckNum_Players()
	local Players = game.Players:GetPlayers()
	if #Players >= 0 then
		return true
	else
		return false
	end
end

while true do
	local Ready = false
	Ready = CheckNum_Players()
	if Ready then
		game.ServerStorage.DisasterEvent:Fire(0, false)
		game.ReplicatedStorage.IsIntermission.Value = true
		for i = 30, 0, -1 do
			inter.Value = i
			wait(1)
		end
		numberOfDisasters = math.random(1, 8)
		local disasterinfo = game.ReplicatedStorage.disasterInfo
		disasterinfo:FireAllClients(numberOfDisasters)
		wait(6)
		if inter.Value == 0 then
			game.ReplicatedStorage.IsIntermission.Value = false

			TeleportPlayers()
			TagAllPlayers("Alive")
			game.ServerStorage.DisasterEvent:Fire(numberOfDisasters, true)
			for i = 120, 0, -1 do
				if #collectionService:GetTagged("Alive") == 0 then
					AwardPlayers()
					TeleportPlayersBackToLobby()
					CleanUp()
					roundtime.Value = 0
					break
				end
				roundtime.Value = i
				CheckPlayersTag("Alive")
				wait(1)
			end
			if roundtime.Value == 0 then
				AwardPlayers()	
				TeleportPlayersBackToLobby()
				CleanUp()
				
			end
		end
	else
		print("Not enough players to start")
	end
	wait(1)
end

I managed to pinpoint the issue, but I’m unsure how to fix it:

In The TeleportBackToLobby function, the teleporting part always breks because the only way you can die in my game is by falling ito the void, and the void deletes the HumanoidRootPart, the thing that gets teleported sseeing as it acts ast the primaryPart for the character. So due to this, the function can’t get the hrp and breaks.

Function

function TeleportPlayersBackToLobby()
	local tp_BackTiles = workspace.TeleportBackTiles:GetChildren()
	for i, v in pairs(game.Players:GetPlayers()) do
		local TileChosen = tp_BackTiles[math.random(1, #tp_BackTiles)]
		local HRP = v.Character:WaitForChild("HumanoidRootPart")
		if HRP and TileChosen:IsA("Part") then
			HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
		else
			repeat 
				HRP.CFrame = TileChosen.CFrame + Vector3.new(0,3,0)
				wait()

			until HRP.CFrame == TileChosen.CFrame + Vector3.new(0,3,0)

			
		end
	end
end

As you can see I tried to fix the issuw by adding a repeat, which isn’t working unfortunately.

So what do I do?

From what I can see you’re effectively running the same code regardless of if the if statement passes or not. To fix this you’d remove all the code that is in the else as it throws an error since it runs if HRP is nil or TileChosen is not a part.

1 Like

But with or without the else, the error still occurs if everyone dies.

Maybe add an invisible kill part just above the void which could make the body parts go invisible on collision, so it looks like the players fell into the void and the HRP stays in the world and doesn’t break? I’m not sure, I haven’t scripted anything myself

1 Like

This probably wont fix your script but just point out that on the first line of the first script there is an extra L in local

1 Like