Music won't stop when gui clicked?

So I made my own script to make the music stop when I pressed a Gui (play button) for a start menu but it won’t work, can anybody tell me what I did wrong? Scary = the music I used btw in the script.

function onClicked(TextButton)
workspace.Parent.Scary.Playing = false
workspace.Parent.Scary.Looped = false
end

script.Parent.MouseButtonClick:connect(onClicked)

3 Likes

workspace.Parent refers to the Game
You should instead change it so it references your Sound object.

The music is in SoundService so would it be workspace.SoundService

It should be game:GetService(“SoundService”):FindFirstChild(“Scary”)

So the new script would be function onClicked(TextButton)
game:GetService(“SoundService”):FindFirstChild(“Scary”)
end

script.Parent.MouseButton1Click:Connect(onClicked)

1 Like

So
for the last line of the code, it should be

script.Parent.MouseButton1Click:Connect(OnClicked)

MouseButtonClick does not exist for GUI Buttons, as far as I know.
Also use :Connect instead of :connect.
:smiley:

Also, that ^

No, the game:GetService(“SoundService”):FindFirstChild(“Scary”) part is the reference or ‘location’ of your Sound object.

You would replace

workspace.Parent.Scary

with

game:GetService("SoundService"):FindFirstChild("Scary") 

I fixed them. Hopefully…

function onClicked(TextButton)

game:GetService(“SoundService”):FindFirstChild(“Scary”)

end

script.Parent.MouseButton1Click:Connect(onClicked)

Would I add .playing = false after game:GetService(“SoundService”)FindFirstChild(“Scary”)?

Yes, but with a capital P.
And also, try removing TextButton from function onClicked(TextButton)?

It didn’t work. (30 charsssssssssss)

function onClicked(TextButton)

game:GetService(“SoundService”):FindFirstChild(“Scary”).Playing = false

end

script.Parent.MouseButton1Click:Connect(onClicked)

I’ll try to figure it out, but thanks for trying to help me.

You should do @Video_2D

function onClicked(TextButton)
workspace.Parent.Scary:Stop() -- do :Stop() no Playing = false or if you want again play it do :Play()
end

script.Parent.MouseButtonClick:connect(onClicked)
1 Like

I’ll try it. (30 charsssssssss)

Thank you, it worked. (30 char)

I did. (30 charssssssssssssssss)