Muting Boomboxes

Hello Devforum!
I am making a game, and it has background music in. I know how to make a mute button for that. I would like to add ‘boomboxes’ into my game, but I want people to be able to mute them if they want to. Is there any way I can do this?

4 Likes

Each time you add a mutable sound to your game, utilise CollectionService and tag that sound. On the client, use GetTagged and loop through the sounds and mute/play them.

You can also use these events to grab newly edited tags
GetInstanceAddedSignal ( string, tag )
GetInstanceRemovedSignal ( string, tag )

3 Likes

Sorry for my little understanding here. I am not really sure on how i would implement that into my game? Happy birthday too :grin:

1 Like

Simply:

local CollectionService = game:GetService("CollectionService") -- Get the service
local TagName = "BoomboxSounds"

local function giveSoundTag(sound)
CollectionService:AddTag(TagName)
-- Give this object the tag

-- When we are done with this object, we can use RemoveTag to remove it
CollectionService:RemoveTag(sound, TagName)
end

local function tagAdded(sound)
wait()
-- This object has a tag
end
local function tagRemoved(obj)
wait()
-- Tag has been removed
end


CollectionService:GetInstanceAddedSignal(TagName):Connect(tagAdded)
CollectionService:GetInstanceRemovedSignal(TagName):Connect(tagAdded)
giveSoundTag(Instance.new('Sound', workspace))

Thank you! :slight_smile:

1 Like

Look at the boombox code to see where the sound is parented, after doing so you can then make a local script and do Sound:Pause() which is a thing I’m pretty sure.

Then to unmute and continue playing, get the current time where the sound is on the server and play it from the client to that timeframe.

1 Like

Super! Would I just put that inside a mute gui, then it works?

It’s simply example code to help you understand the logic with CollectionService, attempt to incorporate it where needed. If you get stuck, send me your code and I’ll try to help you.

Ah I see. Ill give it a go and get back to you, thank you!

2 Likes