workspace.MapInfo.Winner.Changed:Connect(function()
if workspace.MapInfo.Winner.Value == localPlayer.Name then
game.SoundService.Sound.Playing = false
game.SoundService.victorytheme.Playing = true
local sound = game.SoundService.victorytheme
local volume = 0
while volume < 1 do
sound.Volume = volume
volume = volume + 0.1
wait(0.1)
end
while volume > 0 do
sound.Volume = volume
volume = volume - 0.1
wait(0.1)
end
else
game.SoundService.Sound.Playing = true
game.SoundService.victorytheme.Playing = false
end
end)
but the music doesn’t play at all or the duration for the effect is too short. How would I fix this? Would implementing sound tween service be a better option? How would I do it?
It does work that way, but the original music named “Sound” still plays when victorytheme is also playing and the duration of the song is too short
In that case, the audio wouldn’t have enough time to fade and the volume would only decrease by around 0.2.
You may need to decrease the wait value so that it is still able finish the fade before the audio ends, you might also need to add a check for where the sound currently is by using the TimePosition property.
The wait would also have to be below 2.2 seconds (If you aren’t wanting to do anything with the TimePositions)
while volume > 0 and sound.TimePosition == 11 do -- Checks if volume is above 0, and if TimePosition is halfway through. (You can change when you want it to begin fading)
sound.Volume = volume
volume = volume - 0.2 -- Decreases volume twice as fast.
wait(2) -- Waits for 2 seconds each time (You can also change this to match with the TimePosition)
Apologies if this code doesn’t work, I’ve been feeling kind of tired today
local ts = game:GetService('TweenService')
local sound = yoursound
ts:Create(sound,TweenInfo.new(1),{Volume = 0}):Play() -- fade out
ts:Create(sound,TweenInfo.new(1),{Volume = 1}):Play() -- fade in