Can someone help me with my sound issue?

So what I want to do is that the sound will stop when the wave ends not when just all enemies are dead this is my script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local BadgeService = game:GetService("BadgeService")

local events = ReplicatedStorage:WaitForChild("Events")
local mob = require(script.Parent.Mob)
local info = workspace.Info

local round = {}
local votes = {}

function round.StartGame()
	local map = round.LoadMap()
	info.GameRunning.Value = true

	for i = 5, 0, -1 do
		if i <= 6 then
			mob.Spawn("Arrow", 1, map)
		end
		info.Message.Value = "Game starting in " .. i
		task.wait(1)
	end

	local function stopAllMusic()
		for _, sound in pairs(game.SoundService.Music:GetChildren()) do
			if sound:IsA("Sound") and sound.IsPlaying then
				sound:Stop()
			end
		end
	end

	for _, player in pairs(Players:GetChildren()) do
		player.Gold.Value = player.Gold.Value + player.FarmMoney.Value
	end

	for wave = 1, 36 do
		info.Wave.Value = wave
		info.Message.Value = ""
		round.GetWave(wave, map)

		repeat
			task.wait(1)
		until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value

		if not info.GameRunning.Value then break end

		if wave == 36 then
			info.Message.Value = "Victory"
			game.SoundService.Music:ClearAllChildren()
		else
			stopAllMusic()

			local reward = 60 * wave
			for _, player in pairs(Players:GetChildren()) do
				player.Gold.Value = player.Gold.Value + reward
			end

			info.Message.Value = "Wave Reward: $" .. reward
			task.wait(2)

			for i = 2, 0, -1 do
				info.Message.Value = "Next wave starting in " .. i
				task.wait(0.7)
			end

			for _, player in pairs(Players:GetChildren()) do
				player.Gold.Value = player.Gold.Value + player.FarmMoney.Value
			end
		end
	end
end

function round.LoadMap()
	local votedMap = round.ToggleVoting()
	local mapFolder = ServerStorage.Maps:FindFirstChild(votedMap) or ServerStorage.Maps.Tropical
	local newMap = mapFolder:Clone()
	newMap.Parent = workspace.Map

	workspace.SpawnBox.Floor:Destroy()

	newMap.Base.Humanoid.HealthChanged:Connect(function(health)
		if health <= 0 then
			info.GameRunning.Value = false
			info.Message.Value = "GAME OVER"
			game.SoundService.Music:ClearAllChildren()
			workspace.Mobs:ClearAllChildren()
		end
	end)

	return newMap
end

function round.ToggleVoting()
	local maps = ServerStorage.Maps:GetChildren()
	votes = {}
	for _, map in ipairs(maps) do
		votes[map.Name] = {}
	end

	info.Voting.Value = true
	for i = 10, 1, -1 do
		info.Message.Value = "Map voting (" .. i .. ")"
		task.wait(1)
	end

	local winVote, winScore = nil, 0
	for name, mapVotes in pairs(votes) do
		if #mapVotes > winScore then
			winScore = #mapVotes
			winVote = name
		end
	end

	if not winVote then
		local n = math.random(#maps)
		winVote = maps[n].Name
	end

	for _, map in pairs(maps) do
		if map.Name ~= winVote then
			map:Destroy()
		end
	end

	info.Voting.Value = false
	return winVote
end

function round.ProcessVote(player: Player, vote: string)
	for _, mapVotes in pairs(votes) do
		local index = table.find(mapVotes, player.UserId)
		if index then
			table.remove(mapVotes, index)
			break
		end
	end
	table.insert(votes[vote], player.UserId)
	events:WaitForChild("UpdateVoteCount"):FireAllClients(votes)
end

events:WaitForChild("VoteForMap").OnServerEvent:Connect(round.ProcessVote)

function round.GetWave(wave: number, map: Instance)
	if wave == 1 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("They're back again, but stronger.", "Scared")
		wait(5)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Listen up. I heard these new ICU enemies are no joke. So try to survive.", "Scared")
		wait(8)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Help me defend.", "Neutral")
		game.SoundService.Music["???"]:Play()
		mob.Spawn("Zombie", 10, map)
	elseif wave == 2 then
		game.SoundService.Music["???"]:Play()
		mob.Spawn("Zombie", 10, map)
	elseif wave == 3 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("I just noticed that these new enemies have higher defense, so any unit that shoots bullets will do less damage.", "Neutral")
		mob.Spawn("Zombie", 12, map)
		mob.Spawn("Swift", 6, map)
	elseif wave == 4 then
		game.SoundService.Music["Attack"]:Play()
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 8, map)
	elseif wave == 5 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("I think you've got this, you don't need my advice...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("I'll give you a heads-up on something big that's coming.", "Neutral")
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 10, map)
		mob.Spawn("Helfy", 7, map)
	elseif wave == 6 then
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 12, map)
		mob.Spawn("Helfy", 7, map)
	elseif wave == 7 then
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 12, map)
		mob.Spawn("Tremend", 6, map)
		mob.Spawn("Helfy", 9, map)
	elseif wave == 8 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Heads up, a horde is coming in the next wave!", "Scared")
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 15, map)
		mob.Spawn("Tremend", 9, map)
		mob.Spawn("Helfy", 12, map)
	elseif wave == 9 then
		game.SoundService.Music["Attack"]:Play()
		mob.Spawn("Zombie", 25, map)
		mob.Spawn("Swift", 20, map)
		mob.Spawn("Tremend", 15, map)
		mob.Spawn("Helfy", 16, map)
	elseif wave == 10 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Still alive. Good...", "Scared")
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 15, map)
		mob.Spawn("Ignorant", 1, map)
		mob.Spawn("Tremend", 9, map)
		mob.Spawn("Helfy", 12, map)
	elseif wave == 11 then
		mob.Spawn("Zombie", 15, map)
		mob.Spawn("Swift", 12, map)
		mob.Spawn("Ignorant", 2, map)
		mob.Spawn("Tremend", 9, map)
		mob.Spawn("Promp", 8, map)
		mob.Spawn("Helfy", 12, map)
	elseif wave == 12 then
		mob.Spawn("Ignorant", 2, map)
		mob.Spawn("Tremend", 15, map)
		mob.Spawn("Promp", 12, map)
		mob.Spawn("Helfy", 17, map)
	elseif wave == 13 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Something is wrong...", "Scared")
		mob.Spawn("Ignorant", 2, map)
		mob.Spawn("Tremend", 15, map)
		mob.Spawn("Whisper", 3, map)
		mob.Spawn("Promp", 12, map)
		mob.Spawn("Helfy", 17, map)
	elseif wave == 14 then
		mob.Spawn("Ignorant", 3, map)
		mob.Spawn("Tremend", 25, map)
		mob.Spawn("Whisper", 5, map)
		mob.Spawn("Promp", 15, map)
		mob.Spawn("Helfy", 20, map)
	elseif wave == 15 then
		game.SoundService.Music["Breakneck Speed A"]:Play()
		mob.Spawn("Ignorant", 3, map)
		mob.Spawn("Tremend", 25, map)
		mob.Spawn("Whisper", 5, map)
		mob.Spawn("Promp", 15, map)
		mob.Spawn("Hazmat", 2, map)
		mob.Spawn("Helfy", 20, map)
	elseif wave == 16 then
		mob.Spawn("Ignorant", 3, map)
		mob.Spawn("Tremend", 25, map)
		mob.Spawn("Whisper", 5, map)
		mob.Spawn("Promp", 15, map)
		mob.Spawn("Hazmat", 3, map)
		mob.Spawn("Helfy", 20, map)
	elseif wave == 17 then
		mob.Spawn("Ignorant", 3, map)
		mob.Spawn("Tremend", 25, map)
		mob.Spawn("Whisper", 5, map)
		mob.Spawn("Promp", 15, map)
		mob.Spawn("Hazmat", 5, map)		
	elseif wave == 18 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Bringing out the big guns, I see...", "Neutral")
		wait(5)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("I think you've got this. Don't give up!", "Neutral")
		mob.Spawn("Ignorant", 5, map)
		mob.Spawn("Whisper", 12, map)
		mob.Spawn("Promp", 20, map)
		mob.Spawn("Hazmat", 5, map)		
		mob.Spawn("Recon", 2, map)	
	elseif wave == 19 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Something big is incoming in the next wave. Hopefully, you are prepared.", "Neutral")
		mob.Spawn("Ignorant", 5, map)
		mob.Spawn("Whisper", 12, map)
		mob.Spawn("Promp", 25, map)
		mob.Spawn("Hazmat", 6, map)		
		mob.Spawn("Recon", 4, map)	
	elseif wave == 20 then
		game.SoundService.Music["Seek & Destroy"]:Play()
		game.SoundService.Music["Breakneck Speed A"]:Stop()
		mob.Spawn("Ignorant", 10, map)
		mob.Spawn("Whisper", 20, map)
		mob.Spawn("Hazmat", 6, map)		
		mob.Spawn("Recon", 6, map)
		mob.Spawn("Manifest", 1, map)	
	elseif wave == 21 then
		mob.Spawn("Ignorant", 5, map)
		mob.Spawn("Whisper", 15, map)
		mob.Spawn("Hazmat", 12, map)		
		mob.Spawn("Recon", 7, map)
		mob.Spawn("Infantry", 2, map)
		mob.Spawn("Manifest", 1, map)	
	elseif wave == 22 then
		mob.Spawn("Ignorant", 8, map)
		mob.Spawn("Whisper", 12, map)
		mob.Spawn("Hazmat", 12, map)		
		mob.Spawn("Recon", 7, map)
		mob.Spawn("Infantry", 5, map)
		mob.Spawn("Manifest", 1, map)	
	elseif wave == 23 then
		mob.Spawn("Ignorant", 8, map)
		mob.Spawn("Whisper", 15, map)
		mob.Spawn("Hazmat", 12, map)		
		mob.Spawn("Recon", 12, map)
		mob.Spawn("Infantry", 7, map)
		mob.Spawn("Manifest", 1, map)	
	elseif wave == 24 then
		mob.Spawn("Ignorant", 8, map)
		mob.Spawn("Whisper", 15, map)
		mob.Spawn("Hazmat", 12, map)		
		mob.Spawn("Recon", 12, map)
		mob.Spawn("Infantry", 7, map)
		mob.Spawn("Manifest", 2, map)
	elseif wave == 25 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Uhm, is that it? Did we win?", "Neutral")
		wait(5)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Something's not right...", "Neutral")
		game.SoundService.Music["Wave_25"]:Play()
		wait(9)
		mob.Spawn("Cloak", 100, map)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("NO! OUR CLOAKS HAVE BEEN INFECTED! THIS ISN'T GOOD!!!!", "Scared")
		wait(6)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("THERE ARE TOO MANY OF THEM! PLEASE TELL ME YOU'VE GOT THIS!!!", "Scared")
	elseif wave == 26 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Wow... I'm impressed you managed to defeat all the cloaks...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("At this point, I think you don't need my advice, but that doesn't stop me from giving you a heads-up on big threats.", "Neutral")
		mob.Spawn("Ignorant", 12, map)		
		mob.Spawn("Hazmat", 20, map)		
		mob.Spawn("Cloak", 20, map)
		mob.Spawn("Recon", 12, map)
		mob.Spawn("Infantry", 7, map)
		mob.Spawn("Manifest", 2, map)
	elseif wave == 27 then
		mob.Spawn("Ignorant", 12, map)		
		mob.Spawn("Hazmat", 25, map)		
		mob.Spawn("Cloak", 25, map)
		mob.Spawn("Recon", 20, map)
		mob.Spawn("Infantry", 15, map)
		mob.Spawn("Heavy", 2, map)
		mob.Spawn("Manifest", 3, map)
	elseif wave == 28 then
		mob.Spawn("Ignorant", 20, map)		
		mob.Spawn("Hazmat", 25, map)		
		mob.Spawn("Cloak", 25, map)
		mob.Spawn("Recon", 25, map)
		mob.Spawn("Infantry", 20, map)
		mob.Spawn("Heavy", 2, map)
		mob.Spawn("Manifest", 3, map)
	elseif wave == 29 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("Heads up, something big is coming in the next wave. You got this.", "Neutral")
		mob.Spawn("Ignorant", 20, map)		
		mob.Spawn("Hazmat", 25, map)		
		mob.Spawn("Cloak", 30, map)
		mob.Spawn("Recon", 25, map)
		mob.Spawn("Infantry", 20, map)
		mob.Spawn("Heavy", 5, map)
		mob.Spawn("Manifest", 4, map)
	elseif wave == 30 then
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("BIG HORDE INCOMING!!!", "Scared")
		game.SoundService.Music["Oversized"]:Play()
		wait(9)
		mob.Spawn("Cloak", 50, map)
		mob.Spawn("Hazmat", 30, map)		
		mob.Spawn("Infantry", 30, map)
		mob.Spawn("Recon", 35, map)
		mob.Spawn("Manifest", 6, map)
		mob.Spawn("Heavy", 6, map)
		mob.Spawn("Mega Cloak", 1, map)
	elseif wave == 31 then
		mob.Spawn("Cloak", 50, map)
		mob.Spawn("Hazmat", 30, map)		
		mob.Spawn("Infantry", 30, map)
		mob.Spawn("Recon", 35, map)
		mob.Spawn("Manifest", 6, map)
		mob.Spawn("Heavy", 6, map)
		mob.Spawn("Mega Cloak", 2, map)
	elseif wave == 32 then
		mob.Spawn("Cloak", 50, map)
		mob.Spawn("Hazmat", 30, map)		
		mob.Spawn("Infantry", 30, map)
		mob.Spawn("Recon", 35, map)
		mob.Spawn("Manifest", 12, map)
		mob.Spawn("Heavy", 12, map)
		mob.Spawn("Mega Cloak", 2, map)
	elseif wave == 33 then
		game.SoundService.Music["The Last Commandment"]:Play()
		game.SoundService.Music["Oversized"]:Stop()
		mob.Spawn("Cloak", 50, map)
		mob.Spawn("Hazmat", 30, map)		
		mob.Spawn("Infantry", 30, map)
		mob.Spawn("Recon", 35, map)
		mob.Spawn("Manifest", 12, map)
		mob.Spawn("Heavy", 12, map)
		mob.Spawn("Juggernaut", 2, map)
		mob.Spawn("Mega Cloak", 2, map)
	elseif wave == 34 then
		mob.Spawn("Cloak", 50, map)
		mob.Spawn("Hazmat", 30, map)		
		mob.Spawn("Infantry", 30, map)
		mob.Spawn("Recon", 35, map)
		mob.Spawn("Manifest", 12, map)
		mob.Spawn("Heavy", 12, map)
		mob.Spawn("Juggernaut", 2, map)
		mob.Spawn("Mega Cloak", 2, map)
	elseif wave == 35 then
		game.SoundService.Music["The Last Commandment"]:Stop()
		game.SoundService.Music["Oversized"]:Stop()
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("I'm cutting out. .... ...", "Neutral")
		wait(8)
		game.SoundService.Intermediate["Dialog"]:Play()
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("Salutations, dear companion. Your journey has been long, fraught with challenges, yet you've prevailed...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("During your travels, you've met a multitude of your varied brethren scattered across distant lands...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("Only a handful among them will successfully reach this point in their journey...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("Your valorous deeds have affirmed your worthiness, propelling you towards the next stage of your existence...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("The moment has arrived for you to unite with us...", "Neutral")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("You might wonder about the identity of this enigmatic voice, possessing vast knowledge and formidable abilities...", "Neutral")
		wait(12)
		game:GetService("ReplicatedStorage").Events.Dialogue:FireAllClients("May I ask who you are??", "Scared")
		wait(8)
		game:GetService("ReplicatedStorage").Events.DialogueTwo:FireAllClients("I'm delighted you've raised the question...", "Neutral")
		game.SoundService.Music["Dialog"]:Pause()
		game.SoundService.Music["Behind Masks"]:Play()
		wait(13)
		mob.Spawn("Annihilator", 1, map)
		wait(10)	
		mob.Spawn("Juggernaut", 5, map)
		mob.Spawn("Cloak", 100, map)
		mob.Spawn("Mega Cloak", 5, map)
	end

	return round
end

return round
1 Like
newMap.Base.Humanoid.HealthChanged:Connect(function(health)
		if health <= 0 then
			info.GameRunning.Value = false
			info.Message.Value = "GAME OVER"
			game.SoundService.Music:ClearAllChildren()
			workspace.Mobs:ClearAllChildren()
		end
	end)

remove the line game.SoundService.Music:ClearAllChildren() when the enemy dies