Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a music mute button?

Asked by 7 years ago

I have some music with a script like this:

01local sound1 = 949583914
02local sound2 = 918984470
03local sound3 = 390846973
04local music=script.Parent
05 
06 
07while true do
08    wait()
09    music.SoundId="rbxassetid://"..sound1
10    music:Play()
11    music.Ended:wait()
12    wait()
13    music.SoundId="rbxassetid://"..sound2
14    music:Play()
15    music.Ended:wait()
View all 21 lines...

And I tried doing this:

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

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.

0
Btw the music one is a normal script, but the mute on is a local one. sebse456 13 — 7y
0
Is the mute script in a PART or TEXTBUTTON? hellmatic 1523 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
1local Button = script.Parent -- Or where the button is
2local Music = script.Parent.Parent:WaitForChild('Music') -- Or where the music is
3 
4Button.MouseButton1Click:connect(function()
5    Music.Playing = not Music.Playing  -- If playing is true then it makes playing false and reversed
6end)

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

0
Doesn't seem to work. sebse456 13 — 7y
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 User#20388 0 — 7y
0
I did change the path tho. I'm gonna go ahead and check if I did a mistake. I probably didn't tho. sebse456 13 — 7y
0
I did do a mistake. The music was in Workspace. sebse456 13 — 7y
View all comments (2 more)
0
Okay, does it work now? :) User#20388 0 — 7y
0
Yeah. Thanks sebse456 13 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
01local Button = script.Parent
02Music = script.Parent.Parent:WaitForChild("Music")
03 
04Button.MouseButton1Down:Connect(function()
05    if Music.Playing then -- If the music is playing...
06        Music.Playing = not Music.Playing -- Or Music:Pause()
07    end
08    if not Music.Playing then -- If the music is not playing...
09        Music.Playing = true -- Keep playing it
10    end
11end)

Try that.

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 User#20388 0 — 7y
0
Playing is deprecated and it has been since Roblox has upgraded to Lua 5.1. DeceptiveCaster 3761 — 7y
0
My script works, yours kinda does but it works with global variables wich suck and isn't very good as you cannot unmute User#20388 0 — 7y
0
And playing isn't deprecated, it's a propertie dude User#20388 0 — 7y
View all comments (9 more)
0
All yours does is that it stops the music. DeceptiveCaster 3761 — 7y
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. User#20388 0 — 7y
0
In case you don't know, 'not' sets a boolean to the opposite of it's current value User#20388 0 — 7y
0
Then why does that other script of yours not work? DeceptiveCaster 3761 — 7y
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 User#20388 0 — 7y
0
Oh now I see what he did. Hold on a sec. DeceptiveCaster 3761 — 7y
0
Your ifs aren't neccesary, Music.Playing = not Music.Playing is enough User#20388 0 — 7y
0
The second "if" can be used to resume the music if he asks so. DeceptiveCaster 3761 — 7y
0
The music gets resumed the moment playing is on again, and playing gets toggled with the Music.Playing = not Music.Playing User#20388 0 — 7y

Answer this question