Tweening audio volume?

It’s me! …again

I have been trying to “animate” a sound to get gradually louder when a certain IntValue in-game is reached. I’m beginning to wonder if it’s even possible to tween volume.
Here’s my script, I really appreciate the help, along with any other advice!

local surge = game.Workspace:WaitForChild("Values"):WaitForChild("SURGE")
local light = script.Parent.SurfaceLight
local buzz = script.Parent
local TweenService = game:GetService("TweenService")

surge.Changed:Connect(function()
	if surge.Value >= 1000 then
		local info = TweenInfo.new(	
			5,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		)

		local goals =
		{
		Volume = 10;
		}

		local EarPopper = TweenService:Create(buzz, info, goals)
		wait(1)
		EarPopper:Play()
	end
end)
2 Likes

2 notes:

1.You could instead use a simple for loop if you wanted.

2.I have just tested it out and it works perfect.

local surge = game.Workspace:WaitForChild("Values"):WaitForChild("SURGE")
local buzz = script.Sound
local TweenService = game:GetService("TweenService")

surge.Changed:Connect(function()
	if surge.Value >= 1000 then
		local info = TweenInfo.new(	
			5,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.Out,
			0,
			false,
			0
		)

		local goals ={Volume = 10}
		local EarPopper = TweenService:Create(buzz, info, goals)
		EarPopper:Play()
	end
end)
5 Likes

Your script seems fine, are you playing the sound in another script? Can you see if the volume is changing?

Every light in the game has this script for the ‘power surge’ event. Yet none of their volumes are changing when it triggers.

Yours works fine? That’s messed up… what did you do exactly? Maybe I have something else that’s not playing along.

Now I got it! Can’t believe it was that simple… just tweaked the coding a little bit. Thanks for the help.

i know this topic is solved and all but im wondering (since i have this same problem) how you would use a for loop for this?

Using a for loop I would do that:

local audio = workspace:WaitForChild("audioName")

for volume = 1, 0, -0.01 do
	audio.Volume = volume
	wait()
end

audio:Stop()

1 is the initial value of volume
0 is the final value that volume will reach
-0.01 is the step value, meaning volume will decrease by 0.01 on each iteration

2 Likes