Is there a way to know what specific sound is playing

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.

Please and Thank you! :grin:

You can try do the following:

 -- .MouseButton1Click event
if music1:Play() then
    music1:Stop() -- Stopping the current song from playing
end

Then you can try connect it to .MouseButton1Click event and make it so it pauses.

(if any professionals is out there pls correct me if wrong)

1 Like

You could set a variable outside the function which dictates what song is currently playing and check if there is a value:

local CurSong = true
local Music = ...

function UpDate()
 if CurSong then
  -- Code here
 end
end

To mute the current song you would need to simply:

function Mute()
  CurSong:Stop()
end
2 Likes

Ok i will try to write a event between the code

1 Like

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.

1 Like

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
7 Likes