Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make the sound play after the player clicks the button? [EASY!]

I need the sound to also play when they click to close the gui

function close()
script.Parent.Parent.Parent:Remove()
end
	
script.Parent.MouseButton1Click:connect(close)
game.StarterGui.Menu.click:Play() -- the sound

1 comment

0

Just a heads up, you never address the StarterGui, since that stuff automatically gets cloned to the PlayerGui, and thats where you see it.

3 answers

Like what @DarkDanny04 said, you do not use starter gui because that stuff gets cloned into the player gui.

try this:

function close()
	script.Parent.Parent.Parent:Remove()
end
 
script.Parent.MouseButton1Click:connect(close)
game.Players.LocalPlayer.PlayerGui.Menu.click.Play()

3 comments

0

It did not work

0

:Play() - Sound Instances can only be heard in physical environments; you must have it in workspace. :Remove() is deprecated too, use :Destroy().

0

:Remove() is deprecated, use :Destroy(). Lowercase :connect is deprecated, use :Connect().

try this! (I am a newbie at Scripting) put your sound or whatever in SoundService and then put this code

game.SoundService.YourSound.Playing = true

ReplaceYourSound with the name of the sound you want, and again I am a newbie and sometimes I just do the simplest things there maybe better scripts than this, but this is all I have to offer.

1 comment

0

Does this worK?

function close()
	script.Parent.Parent.Parent:Destroy() -- Remove() is deprecated so use :Destroy()
end

script.Parent.MouseButton1Click:Connect(close) -- a lowercase c in Connect makes the function deprecated so please capitalize the C
game.Players.LocalPlayer.PlayerGui.Menu.click:Play()

If it doesn't work, at the end of the script, try adding a wait() time for however long the song is.

This discussion is preserved as it was. New answers, comments, and votes are closed.