So I am trying to make a mute system, but there are too many sounds and I was wondering if there was a way let the script know what specific song is playing at the moment so when the player clicks on the mute button whatever song is playing will pause and once they click it again it will resume.
Reminder :
There are many songs in the game that are on shuffle play
And I simply can not write a script for every song, which means I would have to add multiple mute GUI’s which is not appealing to the player
And I was thinking if I could say something like this
if.music1.Playing = true then
but of course, I would have to do that for over 20 songs.
please let me know any possible ways to shorten it to only one script and
to be able to mute whatever song is playing.
Try looping through all sounds and check Sound.IsPlaying. From this you’d be able to find the sound that is playing (assuming you have multiple sound instances stored somewhere based on your post?)
Something to also note is that using :Stop() (previously mentioned by others) will stop and set the time positon to zero. In this case you’d want to use :Pause() and :Resume() instead in order to maintain time positon and not start the song from the beginning everytime.
Option 1: Abandon pausing and just let the song carry on playing. For this you can use a SoundGroup, set all of the music tracks’ SoundGroup to that, and just set the SoundGroup volume to 0. Restore to 1 when you want to unmute.
Option 2: Change the way your system works so you have only 1 Sound object and when you want to play a different song, just swap the SoundId instead of the object that you want to play. That way you can just pause it and know that’s the only one playing.
Option 3:
--- Pausing...
for _, sound in ipairs( YourSoundFolder:GetChildren() ) do
if sound:IsA( 'Sound' ) and sound.IsPlaying then
sound:Pause()
end
end
--- And Resuming...
for _, sound in ipairs( YourSoundFolder:GetChildren() ) do
if sound:IsA( 'Sound' ) and sound.IsPaused then
sound:Resume()
end
end