How to make sound play when you click a button and make it stop when you press other buttons?

  1. What do you want to achieve?
    Pretty simple. I want to make sound loop, when you press a text button, until you click another text button (in this case back) which will stop it.

  2. What is the issue?
    This is my script:
    image

  3. What solutions have you tried so far? Tried looking a tutorial, checked AlvinBlox’s, but it didn’t work…

3 Likes

Stuff in startergui is replicated to playergui so keep that in my mind

local Play = plr.PlayerGui:WaitForChild("ScreenGui").Cam1AButton
local Stop = "PATH"
local Sound = Play.Sound

Play.MouseButton1Click:Connect(function()
    Sound:Play()
    Sound.Looped = true
end)

Stop.MouseButton1Click:Connect(function()
    Sound:Stop()
    Sound.Looped = false
end)
2 Likes

Hello, I tried the script and this is what I got:
image

Also, my script is inside here:
image

Do you know what is wrong here?

3 Likes

I assume the script inside of “Cam1A” is the one that is activating this button, so:

script.Parent.MouseButton1Click:Connect(function()
   script.Sound:Play()
end)

-- Now put the code below in the button that is supposed to stop the sound

script.Parent.MouseButton1Click:Connect(function()
   script.Sound:Stop()
end)

You can’t target an item using “script.Cam1A” when the script is not the parent of Cam1A, thus you can use “script.Parent” to refer to it instead.

1 Like

Thats because you didn’t define the plr variable, try using a PlayerAdded event. and defining plr in one of the parameters.

1 Like

Hello, the comment above you was the solution, but thanks a lot for helping!

You should mark it as a solution to prevent posts like mine lol.

1 Like