Hi, i am making a sound that has a localscript that fades the sound inside of it so if it gets called to play by a localscript it will fade in and play, however it does not fade out but just stops instantly?

local targetvolume = 0.5
script.Parent.Played:Connect(function()
	script.Parent.Volume = 0
	while wait() do
		if script.Parent.Volume <= targetvolume -0.01 then
			script.Parent.Volume = script.Parent.Volume + 0.01
		elseif script.Parent.Volume == targetvolume then
			break
		end
	end
end)

script.Parent.Ended:Connect(function()
	while wait() do
		if script.Parent.Volume >= 0.01 then
			script.Parent.Volume = script.Parent.Volume - 0.01
		elseif script.Parent.Volume == 0 then
			break
		end
	end
end)

3 comments

0

The function runs right when it ends, you want the script to run like 5 seconds before it ends

0

How would i detect that?

0

Nevermind, thanks!