Does anyone know how to make a mute button

does anyone know how to make a mute button if you used a playlist from this vid >ROBLOX Scripting Tutorial - How to make a (looped) Music Playlist!! (MODEL IS HERE!) - YouTube because that vid didnt have the part where you could add a mute button and i need a script for it


this is the serverscript that i used for the soundplaylist from the video

2 Likes

Have you tried searching on how to make a music playlist and stuff like that on the devforums?
If you havent (which you should) I think this tutorial might help you.

3 Likes

is there the same tutorial liek that but doesnt have the feature where you can skip the song or see what the song title is

2 Likes

You dont have to follow the entire tutorial. You can just add that mute feature without adding those other features.

2 Likes

Suggestion, post some code, nobody knows how your script works so they will likely not be able to help. Don’t assume everyone will watch the tutorial video that you followed.

1 Like

this was the script i used from the video tutorial


i tried looking for a similar tutorial with this same script but with a mute button feature
but i couldnt find one

keep in mind that i didnt add sounds to a folder

Just make the button set all the music to have a volume of 0 for the client. I’;m guessing by button you mean a GuiButton?

1 Like

yes
im talking about a GUI button to mute but i couldnt find any scripts for it

Is that a localscript or a script? If its on the server, you may have a problem muting it for a specific client.

Add a localscript inside that button and do this

local button = script.Parent

local musicFolder = workspace.SoundPlaylist

local mute = false

button.MouseButton1Click:Connect(function()
	for i,v in pairs(musicFolder:GetChildren()) do
		if not v:IsA("Sound") then continue end
		if mute then
			v.Volume = 0.5 --Or whatever the original volume is
		else
			v.Volume = 0
		end
	end
	mute = not mute
end)

This code will loop through all the sounds in the folder and sets them to hae a volume of 0.5 or 0 depending on the mute variable, and then at the end, inverts the variable so if it was false, it becomes true and vice versa

2 Likes

that script for those sounds isnt a localscript

Try the script I made out and see if it’ll work

Do you have your own music system or do you add music using commands?

1 Like

He has his own that plays 2 music tracks, his code for how it plays is up above

1 Like
local Button = -- Define button
local Music = -- Define music
local Music2 = -- Define other music

local function muteMusic(actionName, inputState, inputObj)
		
		
		if Music.Volume == 0 then
			
			Music.Volume = 0.5
	else
		 Music.Volume = 0
    elseif Music2.Volume == 0 then
         Music2.Volume = 0.5
    else 
        Music2.Volume = 0
	end
end

button.MouseButton1Click:Connect(muteMusic)

-- This should probably work I guess, update it if you want it to work a different way
-- If this doesn't work, just use this part and just replace the sound id once the music ended

local Button = -- Define button
local Music = -- Define music

local function muteMusic(actionName, inputState, inputObj)
		
		if Music.Volume == 0 then
			
			Music.Volume = 0.5
	else
		 Music.Volume = 0
         
         if Music.Ended then
          wait(5)
          Music.SoundId = "" -- Paste the sound id
	end
end

button.MouseButton1Click:Connect(muteMusic)
1 Like

That would kinda be more work than it should, it’s better to disable all the music when the button is pressed rather than disable only one, like how I did

1 Like

Though you’re right, the other method I sent below would work like that, they just have to change the soundid from the current script.

Again, it’s kinda avoiding the simplest way to go about it which is to set all the of musics’ volumes to 0 when wanting to mute and 0.5 when wanting to unmute

what if the sounds i added arent in a folder

I would do something like… making a localscript and putting in startergui. Adding a screengui to startergui and textbutton inside the screengui then add this code to the local script.

local TextButton = script.Parent.ScreenGui.TextButton

TextButton.MoiseButton1Down:Connect(function())

if not mute then
mute = true
else
mute = false
end

for _,music in ipairs(game.SoundService:GetChildren())
do

if mute then

if music.Playing then
music.Volume = 0
end
end

if not mute then

if music Volume == 0 then
music.Volume = (something greater then 0)
end
end

end)

I’m sorry it’s so disorganized, I’m on my phone.

This script requires all the songs to be placed in game.SoundService