Making a sound not play after the player has pressed a text button

I’m making a horror game and I’m working on the UI and I want the creepy music to stop playing when the player has pressed “Play” on the screen I have put the sound in the workspace and the script inside the play text button is:
script.Parent.MouseButton1Click:Connect(function()

script.Parent.Parent.Visible = false

game.Workspace["Scary/Creepy Music Box"].playing = false

game.Workspace["Scary/Creepy Music Box"].Looped = false

end)

and the music does not stop

You can use Sound:Stop()

local sound = game.Workspace.CreepySound
local textbutton = script.Parent

textbutton.MouseButton1Click:Connect(function()
textbutton.Visible = false
sound:Stop()
end)
2 Likes

There’s a function called Sound:Stop(), use it to cease the sounds from it.

However, you need to use the correct type of script and parenting them to the right place. LocalScript should be recommended for the GUI input and depending on the intended behavior, either allow the client to stop it to themselves or the server by sending the signal to the server.

I tried this the sound stopped but the UI did not disappear

script.Parent.Parent instead of script.Parent, just a slight error.

oh thank you so much, i appreciate it

It should be .Playing, not .playing
and there’s a function to pause and stop the song;
image
(Press the image for the Roblox Developer link)

its not working, sorry I’m very new to scripting is this layout a problem by any chance?

You added in another parent, which means you’re referring to the frame. Remove that parent.

I tried it removing the other parent it did not work

If im not referring to the frame only the play button disappears, im going to try something

@dragon21x50, remake:

script.Parent.MouseButton1Click:Connect(function()
        script.Parent.Visible = false
        game:GetService("Workspace"):WaitForChild("Scary/Creepy Music Box"):Stop()
end)
1 Like

You didn’t even start it? First use sound:Play() before the function.

sorry, and also sorry for not responding, and someone already messaged me the right one

it did! Thank you so much, i was trying for so long thanks for the answer

Oh i forgot to mark it, thank you for reminding me