basically, if i set my music 2 times in a row right when the volume is going up it just stays at 0 volume.
please tell me how i can improve this script because i am feeling like its NOT the best…
local music = workspace:WaitForChild("music")
local plr = game.Players.LocalPlayer
local downvoluming = false
local upvoluming = false
local DOWNVOLUMENOWEXCLAMATIONMARK = false
local curID = 0
local curpitch = 1
local curfullvol = 1
local curfadeouttime = 1
local curfadein = 1
local curbonuses = {}
local whatithastobe = 1
local muted = false
function changemusics(musicID, pitch, defaultVOL, fadeouttime, fadeintime, bonuses)
if musicID == curID then return end
local OURfullvol = defaultVOL
curID = musicID
curpitch = pitch
curfullvol = defaultVOL
curfadein = fadeintime
-- why do i save these values instead of just using them when i have to set the music id or whatever else? so that if we fully downvolume we set the music to the latest requested music.
print(downvoluming
,upvoluming
,DOWNVOLUMENOWEXCLAMATIONMARK)
if upvoluming then
DOWNVOLUMENOWEXCLAMATIONMARK = true
curfadeouttime = fadeouttime
return
end
if not downvoluming then
downvoluming = true
local fadeoutnow = curfadeouttime
local fullvol = music.Volume
for i = 1, fadeoutnow * 100, 1 do
whatithastobe = fullvol * (1 - i/(fadeoutnow*100))
if not muted then music.Volume = whatithastobe else music.Volume = 0 end
task.wait(.01)
end
downvoluming = false
curfadeouttime = fadeouttime
else
curfadeouttime = fadeouttime
return
end
task.wait(curfadeouttime*1.65) -- so that the music doesnt instantly come back.
music.TimePosition = 0
music.SoundId = "rbxassetid://"..tostring(curID)
music.PlaybackSpeed = curpitch
if not upvoluming then
upvoluming = true
for i = 1, curfadein*100, 1 do
if DOWNVOLUMENOWEXCLAMATIONMARK == true then -- emergency fade out if we have to switch music when its getting upvolumed.
local musnow = music.Volume
DOWNVOLUMENOWEXCLAMATIONMARK = false
downvoluming = true
for i = 1, (musnow/OURfullvol)*100, 1 do
whatithastobe = musnow * (1 - i/((musnow/OURfullvol)*100))
if not muted then music.Volume = whatithastobe else music.Volume = 0 end
task.wait(.01)
end
downvoluming = false
break
end
whatithastobe = curfullvol * (i/(curfadein*100))
if not muted then music.Volume = whatithastobe else music.Volume = 0 end
task.wait(.01)
end
upvoluming = false
end
end
game.ReplicatedStorage.remoteevents.setmusic.OnClientEvent:Connect(changemusics)
game.ReplicatedStorage.remoteevents.setmusicCLIENT.Event:Connect(changemusics)
if someone doesnt understand what i mean i could clarify it tommorow, very sorry but i have to go right now…