How can i make a sound that can be activated and deactivated when a gui button is clicked

I have so far made a GUI button that only appear for me, but I do not know what I can do for the GUI button to actually activate a sound by clicking a GUI button and deactivate it by clicking the GUI button again.

1 Like

Use sound:Play() and sound:Stop() to do this. I recommend you read this: Sound | Documentation - Roblox Creator Hub

I still dont understand it
like what kind of full script do i create
since im not really a scripter but more of a builder

1 Like

try this:

local bop = false
script.Parent.MouseButton1Down:connect(function()
if bop == false then
soundname:Play()
else
soundname:Stop()
end
end)

is there an id that i have to put somewhere?

nope. Just name the sound “bip” and parent it to the button and do:
“script.Parent.bip” instead of “soundname”. Should work.
Cheers! My first comment to get “solution” on it!

1 Like

thats helpfull but will the audio be looped?

There is a property for the sound named “Lopped”. Click the checkbox next to the property to have it loop.

1 Like

Ok thats all i needed, Thanks!
i have a good day

1 Like

Im clicking the gui button and the sound script isnt working
is there some kind of placement problem or should it be a local script
Picture of studio

Does it give you any errors in the output when clicking the button?

Im not seeing any errors when i click the button
should i place a clickdetector?

he buttons don’t need click detectors. Are you using both a local and a server script?

wait should the sound thing be a local script?
the other local script i named “no” is for only me to access the gui

It has always worked for me only on a local script. I suggest you do that.

Okay i made it a local script and when i click it , it plays the audio but when i click it again it just replays the audio

Copy and paste the script as a comment in case you did something wrong.

ive checked and i can send you the picture of the local script, here
script

I have no idea whats happening but I have an alternative. Try this:

local bop = false
script.Parent.MouseButton1Down:connect(function()
if bop == false then
script.Parent.bip.PlaybackSpeed = 1
else
script.Parent.bip.PlaybackSpeed = 0
end
end)

Well now it just doesnt work at all