Sound Regions Issue

For some reason when I reset in a previously sound region it’ll stop playing the in the song in the new sound region when I enter the next sound region, here’s the sound regions script if you wanna take a look at it:

Edit: It doesn’t stop, when I die or reset in a previous sound region it fades in but only fades in once and that’s it; but for some reason If I don’t reset nor die it fades in 11 times.

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

local SoundTable = {}

for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
	table.insert(SoundTable, game.Workspace.SoundRegions2[v.Name].Volume)
	wait(0.2)
end

local Found = false


while wait(.5) do

	for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
		local sound = game.Workspace.SoundRegions2[v.Name]

		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
		local player = game.Players.LocalPlayer
		local character  = player.Character or player.CharacterAdded:Wait() --waits until character exists
		local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


		for _, part in pairs(parts) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				print("Player Was Found")
				Found = true
				break
			else
				Found = false
				print("Player Not Found")
			end
		end


		if Found == true and sound.IsPlaying == false then
			wait(0.1)
			sound:Play()
			for i = 0, SoundTable[i], 0.05 do
				sound.Volume = i
				wait(0.1)
				print"Sound Faded In"
				if sound.Volume == SoundTable[i] then
					print("Sound Faded In")
					break
				end
			end
		end


		if Found == false and sound.IsPlaying == true then
			wait(0.1)
			print("Waited")
			for i = SoundTable[i], 0, -0.05 do
				print("Fading Out")
				sound.Volume = i
				wait(0.1)
			end
			sound:Stop()
		end
	end
end

Let me know if you need more information on the bug!

1 Like

I fixed the bug partially, not fully I just made the music fade in and out if it didn’t fade in or out after I reset in a different difficulty…

Here’s the script:

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

local SoundTable = {}

for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
	table.insert(SoundTable, game.Workspace.SoundRegions2[v.Name].Volume)
	wait(0.2)
end

local Found = false


while wait(.5) do

	for i, v in pairs(SoundRegionsWorkspace:GetChildren()) do
		local sound = game.Workspace.SoundRegions2[v.Name]

		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
		local player = game.Players.LocalPlayer
		local character  = player.Character or player.CharacterAdded:Wait() --waits until character exists
		local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


		for _, part in pairs(parts) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				print("Player Was Found")
				Found = true
				break
			else
				Found = false
				print("Player Not Found")
			end
		end


		if Found == true and sound.IsPlaying == false then
			wait(0.1)
			sound:Play()
			print("Played")
			for i = 0, SoundTable[i], 0.05 do
				sound.Volume = i
				wait(0.1)
				print("Sound Faded In")
				print(i)
				if sound.Volume == 0 then
					sound.Volume = 0.1
					sound.Volume = 0.2
					sound.Volume = 0.3
					sound.Volume = 0.4
					sound.Volume = 0.5
				else
					if sound.Volume == SoundTable[i] then
					print("Sound Faded In")
					break
				end
				end
			end
		end


		if Found == false and sound.IsPlaying == true then
			wait(0.1)
			print("Waited")
			for i = SoundTable[i], 0, -0.05 do
				print("Fading Out")
				sound.Volume = i
				wait(0.1)
				if sound.Volume == 0 then
					sound.Volume = 0.4
					sound.Volume = 0.3
					sound.Volume = 0.2
					sound.Volume = 0.1
					sound.Volume = 0
				end
			end
			sound:Stop()
		end
	end
end