Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a music mute button?

I have some music with a script like this:

local sound1 = 949583914
local sound2 = 918984470
local sound3 = 390846973
local music=script.Parent


while true do
	wait()
	music.SoundId="rbxassetid://"..sound1
	music:Play()
	music.Ended:wait()
	wait()
	music.SoundId="rbxassetid://"..sound2
	music:Play()
	music.Ended:wait()
	wait()
	music.SoundId="rbxassetid://"..sound3
	music:Play()
	music.Ended:wait()
	wait()
end

And I tried doing this:

script.Parent.MouseButton1Click:connect(function()
	script.Parent.Parent.Parent.Parent.Parent.Music.Volume = 0
end)

I don't know what I did wrong. You might not even be able to change the volume like that. I need it to be fully local too.

2 comments

0

Btw the music one is a normal script, but the mute on is a local one.

0

Is the mute script in a PART or TEXTBUTTON?

2 answers

✓ Accepted answer
local Button = script.Parent -- Or where the button is
local Music = script.Parent.Parent:WaitForChild('Music') -- Or where the music is

Button.MouseButton1Click:connect(function()
	Music.Playing = not Music.Playing  -- If playing is true then it makes playing false and reversed
end)

Should explain itself, if you don't understand it, just ask :)

6 comments

0

Doesn't seem to work.

0

I tried it and it worked, make sure the script is inside the button and the sound is next to the button called 'Music', or change the variables (line1 + line2) to change where the sound and button are

0

I did change the path tho. I'm gonna go ahead and check if I did a mistake. I probably didn't tho.

0

I did do a mistake. The music was in Workspace.

0

Okay, does it work now? :)

0

Yeah. Thanks

local Button = script.Parent
Music = script.Parent.Parent:WaitForChild("Music")

Button.MouseButton1Down:Connect(function()
	if Music.Playing then -- If the music is playing...
		Music.Playing = not Music.Playing -- Or Music:Pause()
	end
	if not Music.Playing then -- If the music is not playing...
		Music.Playing = true -- Keep playing it
	end
end)
	

Try that.

13 comments

0

Your script isn't wrong but my script is right, please go learn scripting before trying to correct me as I tried my script, actually IsPlaying is wrong as it is READ ONLY. Also your script doesn't start again when pressed

0

Playing is deprecated and it has been since Roblox has upgraded to Lua 5.1.

0

My script works, yours kinda does but it works with global variables wich suck and isn't very good as you cannot unmute

0

And playing isn't deprecated, it's a propertie dude

0

All yours does is that it stops the music.

0
  1. You use a clickdetector what means your script won't work because FE 2) You're wrong, I use not wich means that it sets it to true if it's false and reversed.
0

In case you don't know, 'not' sets a boolean to the opposite of it's current value

0

Then why does that other script of yours not work?

0

It does work, he probably didn't change the 2 variables wich say where the sound and the button are, I tested it and it worked

0

Oh now I see what he did. Hold on a sec.

0

Your ifs aren't neccesary, Music.Playing = not Music.Playing is enough

0

The second "if" can be used to resume the music if he asks so.

0

The music gets resumed the moment playing is on again, and playing gets toggled with the Music.Playing = not Music.Playing

This discussion is preserved as it was. New answers, comments, and votes are closed.