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 6 years ago

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.

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

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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 :)

0
Doesn't seem to work. sebse456 13 — 6y
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 — 6y
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 — 6y
0
I did do a mistake. The music was in Workspace. sebse456 13 — 6y
View all comments (2 more)
0
Okay, does it work now? :) User#20388 0 — 6y
0
Yeah. Thanks sebse456 13 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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.

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

Answer this question