SoundRegion fades in normally, but cuts off abruptly

I’m working on a game that requires tweened volume changes between SoundRegion sounds. Below is the typical SoundRegion script with some minor adjustments to make it so the volume tweens between regions rather than changing abruptly:

local plr = game.Players.LocalPlayer
local sr = workspace:WaitForChild("SoundRegions")
local ts = game:GetService("TweenService")
sr = sr:GetChildren()

local smanage =  {}

for _,region in pairs(sr) do
	local info = {}
	local region3 = Region3.new(region.Position-(region.Size/2), region.Position+(region.Size/2))
	region.Transparency = 0.8
	region.CanCollide = false
	
	info.Region = region3
	info.Sound = script.SoundRegions:FindFirstChild(region.Name).Sound
	
	table.insert(smanage,info)
end

game:GetService("RunService").RenderStepped:Connect(function()
	for _,soundInfo in pairs (smanage) do
		local region = soundInfo.Region
		local sound = soundInfo.Sound
		local parts = workspace:FindPartsInRegion3WithWhiteList(region, plr.Character:GetDescendants())
		
		local voluptween = ts:Create(sound, TweenInfo.new(1), {Volume = 1}, true)
		local voldowntween = ts:Create(sound, TweenInfo.new(1), {Volume = 0}, true)
		
		if #parts > 0 then
			if not sound.IsPlaying then
				sound:Play()
				voluptween:Play()
			end
		else
			voldowntween:Play()
			voldowntween.Completed:Connect(function()
				sound:Stop()
			end)
		end
	end
end)

I understand the problem lies within the last few lines, where sound:Stop() is, but waiting for the tween to finish and then cutting the sound off sometimes leads to the sound “flickering” back on when the region is reentered (other times not, for whatever reason). I’m more making this post to ask if there is a better way to do this. Maybe I’m going about it entirely wrong, but hopefully it’s just a property I’m unaware of or a rather simple fix. Thanks in advance!

If your regions do not overlap why not just use sound in your regions with a rolloff property enabled and set to Inverse Tapered? Ive seen it done in tutorial but never dealt with it in game.

As @RMofSBI said, you can use Sound.RollOffMaxDistance to make your sound fade in or out depending on which Part the Sound is based in.

Looks like they’ve redone the webpage.
Here’s the new link:

1 Like

Using rolloff is cumbersome and not easy to manipulate. I like using SoundRegions, hence why I made them the point of this article. I appreciate this idea, but I’m not using it. There are parts where I want the outdoor ambience to switch immediately to an indoor ambience, and not all of these indoor spaces are of a regular shape. The control provided by SoundRegions is what works best for me.

What is this part trying to accomplish? are you disconnecting from the function?

Making the original sound stop so the next one can be played as soon as the tween stops. But, it’s a bit hacky and I don’t like it. Idk where you got the part that I’m “disconnecting” from the function, though. When I just tween the volume down without stopping the audio, though, after entering another region and re-entering the previous one the sound just doesn’t play.

Have you tried to cancel the tween after playing and before stopping the sound (you can play with the time i just added a one second wait)?:

I could try that, didn’t know :Cancel() was a property