-
What do you want to achieve?
I’m trying to make a horn sound with a smooth fade-in and fade-out. The horn sound would fade in (volume increase) when the “h” key is pressed, and it would fade out when the same key is released. -
What is the issue?
When I try the code below, no sound plays at all. I looked at the TweenService documentation, but I’m still clueless. -
What solutions have you tried so far?
None. The horn sounds pretty ugly when it’s just enabled and disabled abruptly, so I could really use a solution that won’t cause a memory leak or something.
mouse.KeyDown:connect(function(key)
if key == "h" then
tweenService:Create(Value,TweenInfo.new(0.5), {Volume = 1}):Play()
end
end)
mouse.KeyUp:connect(function(key)
if key == "h" then
tweenService:Create(Value,TweenInfo.new(0.5), {Volume = 0}):Play()
end
end)
“Value” is actually the Sound object. My system uses a different approach than just fetching a Sound object right off the bat.
Tweening is still pretty new to me. I’m not asking for anyone to make code for me, I just need help with getting my horn sound to play with smooth transitions. I could use a “for” statement, but that isn’t as efficient as tweening. I seek no interest in changing the volume of the sound numerous times with a wait() in between, as that’s even more inefficient.
I’d also look to point out that I know for a fact that the non-sound-related code, like the keybind input and other things, are not the problem. The sound does play without tweening, but again, it sounds really ugly when it just goes on and off without any kind of fading. The code does fetch TweenService, but I excluded it from the extraction above.