I am trying to make a lobby in game music and i am trying to figure out how to make the sound fade in when new song and when fade out towards the end of the song for 6 songs that plays right after each other. Here is what i have so far:
while true do wait() game.Workspace.S1:Play() wait(125) game.Workspace.S1:Stop() game.Workspace.S2:Play() wait(125) game.Workspace.S2:Stop() game.Workspace.S3:Play() wait(125) game.Workspace.S3:Stop() game.Workspace.S4:Play() wait(125) game.Workspace.S4:Stop() game.Workspace.S5:Play() wait(125) game.Workspace.S5:Stop() game.Workspace.S6:Play() wait(125) game.Workspace.S6:Stop() end
This is just a script in workspace with the 6 sound holders in workspace as well. Please help! Thanks!
local ValidIds = {366306298} -- Enter your sound ids here function PlaySong() -- Function local Sound = Instance.new("Sound",game.Workspace) -- Create a new Sound Sound.Name = "LobbyMusic" -- Name the Sound Sound.SoundId = "http://www.roblox.com/asset/?id=" .. ValidIds[math.random(1,#ValidIds)] -- Pick a random sound from the table(ValidIds) Sound.Volume = 0 -- Change the Volume to 0(For fading in) Sound.Pitch = 1 -- Change the pitch, default is 0.5 wait(1) -- Wait 1 second to play it Sound:Play() -- Play the song for i = 1,50 do -- Fade in wait(0.1) -- If this isn't here it'll be instant Sound.Volume = Sound.Volume + 0.05 -- Change the volume end -- End the for i = 1,50 repeat wait() until Sound.TimeLength > 10 -- Cause it won't work properly without this, wait til the song length is above 10 seconds(you can change this if needed) wait(Sound.TimeLength - 1) -- Wait til the song is over - 1 second for i = 1,50 do -- Fade out wait(0.1) -- If this isn't here it'll be instant Sound.Volume = Sound.Volume - 0.05 -- Change the volume end -- End the for i - 1,50 Sound:Stop() -- Stop the song(in-case it didn't stop yet) Sound:Destroy() -- Deletes the song end -- End the function PlaySong() -- Play a song while wait(125) do -- Loop PlaySong() -- Play a song forever :D end -- End the loop
If you do not want to use my full script, the only actual part you need for fading in is:
for i = 1,50 do wait(0.1) Sound.Volume = Sound.Volume + 0.05 end
Same for fading out:
for i = 1,50 do wait(0.1) Sound.Volume = Sound.Volume - 0.05 end
If you have any questions, comment on the answer and I'll try to help you.