Music Resetting on Death, Also Fading Help

I have a region based music script and don’t know why when I press mute button and die the music will turn back on… I’m thinking of removing all kill bricks but if you guys know a better way.

also how would I be able to add sound fading?
I know about I 1,50 for sound.volume -1 but when I tried to add it to the stop() part couldn’t get it to work…

(just read about Resetgui on death its already flipped off, not working.)

script in question

local soundregionworkspace = game.Workspace:WaitForChild("SoundRegions")

local Found = false

while wait(1) do
	for i, v in pairs(soundregionworkspace:GetChildren()) do
		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
		local part = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
		for _, part in pairs(part) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				Found = true
				break
			else
				Found = false
			end
		end
		if Found == true then
			if script.Parent.RegionSongs[v.Name].IsPlaying == false then
				script.Parent.RegionSongs[v.Name]:Play()
				break
			end
		else
			script.Parent.RegionSongs[v.Name]:Stop()
		end
	end
end

and



local music = {'troll'}
local db = true
script.Parent.MouseButton1Click:Connect(function()
	if db == true and music then
		db = false
		script.Parent.MUTE.Text = ("UNMUTE")
		script.Parent.Parent.Parent.Parent.SongAreas.Disabled = true
		script.Parent.Parent.Parent.Parent.RegionSongs.LobbySong.Playing = false
		
		script.Parent.Parent.Parent.Parent.RegionSongs.bonus1.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bonus2.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bonus3.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bonus4.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bonus5.Playing = false
		
		script.Parent.Parent.Parent.Parent.RegionSongs.bosslvl1.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bosslvl2.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bosslvl3.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bosslvl4.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.bosslvl5.Playing = false
		
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage1Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage2Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage3Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage4Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage5Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage6Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage7Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage8Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage9Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage10Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage11Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage12Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage13Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage14Song.Playing = false
		script.Parent.Parent.Parent.Parent.RegionSongs.Stage15Song.Playing = false
	else
		db = true
		script.Parent.MUTE.Text = ("MUTE")
		script.Parent.Parent.Parent.Parent.SongAreas.Disabled = false
	end
end)
1 Like

I don’t know an exact solution to your first issue but the question about sound fading you can use
TweenService to achieve that.

Also I recommend using pairs to disable sounds instead of doing it individually.

if db == true and music then
	db = false
	script.Parent.MUTE.Text = ("UNMUTE")
	script.Parent.Parent.Parent.Parent.SongAreas.Disabled = true
	for i, v in pairs(script.Parent.Parent.Parent.Parent.RegionSongs:GetChildren()) do
		if v:IsA("Sound") then
			v.Playing = false
		end
	end
else
	db = true
	script.Parent.MUTE.Text = ("MUTE")
	script.Parent.Parent.Parent.Parent.SongAreas.Disabled = false
end
1 Like

yeah I was thinking of setting up a pair since they are all in same folder! to clean it up, I gotta ask though how would debounce be able to turn sound volume down? would I still need to add a
sound.volume?

To be honest I don;t understand your question abut if you wan’t to turn off sound then you can use either Sound:Pause() or Sound.Volume = 0

local MusicDebounce = true
script.Parent.MouseButton1Click:Connect(function()
	if MusicDebounce then
		MusicDebounce = false
		for i, v in pairs(script.Parent.Parent.Parent.Parent.RegionSongs:GetChildren()) do
			if v:IsA("Sound") then
				v.Volume = 0
				--Or
				v:Pause()
			end
		end
	else
		MusicDebounce = true
		for i, v in pairs(script.Parent.Parent.Parent.Parent.RegionSongs:GetChildren()) do
			if v:IsA("Sound") then
				v.Volume = 1
				--Or
				v:Play()
			end
		end
	end
end)
1 Like

kk that answered! thanks for the inside :open_mouth: hope it works