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

How do I play a sound on MouseButton1Down on a GUI?

I have the following script for a GUI and I want to use this sound http://www.roblox.com/asset/?ID=142448886

textButton = script.Parent
textButton.MouseButton1Down:connect(function()
	if textButton.Text == "Open" then
		textButton.Text = "Close"
		 textButton.BackgroundColor3 = Color3.new(1, 0, 0)
	elseif textButton.Text == "Close" then
		    textButton.Text = "Open"
			 textButton.BackgroundColor3 = Color3.new(0, 1, 0)
	end
end)

1 answer

✓ Accepted answer
local NAMEHERE = Instance.new("Sound") -- creates a new sound if you dont have it already
NAMEHERE.SoundId = "http://www.roblox.com/asset/?id=142448886" -- inserts the id you gave me
NAMEHERE.Parent = script.Parent -- puts the sound in the gui

textButton = script.Parent - your script
textButton.MouseButton1Down:connect(function()
    if textButton.Text == "Open" then
        textButton.Text = "Close"
		NAMEHERE:Play() -- or :Stop() my script
         textButton.BackgroundColor3 = Color3.new(1, 0, 0)
    elseif textButton.Text == "Close" then
            textButton.Text = "Open"
			NAMEHERE:Play() -- or :Stop() my script
             textButton.BackgroundColor3 = Color3.new(0, 1, 0) -- your script
    end
end)

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