I have been trying to reduce the music in my game with a while loop, however since you can change the volume of the music as a player, the amount of volume decrease per tick needed to hit volume 0 is different depending on the start volume.
local function playClick()
while script.Parent.Parent.darken.Transparency >= 0 do
wait(0.01)
script.Parent.Parent.darken.Transparency -= 0.02
game.SoundService.menuMusic.Volume -= 0.666/50
end
end
playB.MouseButton1Click:Connect(playClick)
I figured it out just before you replied. For some reason I thought it would update the variable even while in the loop, but of course the loop locks the script in those lines (as I understand it now).
local function playClick()
local startVol = game.SoundService.menuMusic.Volume
while script.Parent.Parent.darken.Transparency >= 0 do
wait(0.01)
script.Parent.Parent.darken.Transparency -= 0.02
game.SoundService.menuMusic.Volume -= (startVol/100)*2
print(startVol)
end