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

How do I make audio work?

I want a sound to play after clicking an image button, and I'm new to using audio and really having trouble with making this work.

function onButtonClick()
	script.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.PacksFrame.Visible = true
	script.Parent.Parent.Parent.StoreFrame.Visible = false
	script.Parent.Parent.Parent.PlayFrame.Visible = false
	script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Workspace.ClickSound.IsPlaying = true
	script.Parent.Parent.Parent.Parent.NowViewing.Text = "Now Viewing: Packs"
end

script.Parent.MouseButton1Click:connect(onButtonClick)

2 answers

If you want to play and audio, you use the :Play() method, like so:

Sound:Play() --This will play the sound from the beginning

If you want the audio to stop, you use the :Stop() method, like so

Sound:Stop() --This will make the sound stop

You can find more information about audio here: Audio

Hope this helped!

It's very simple, there is a function which is :Play() for sounds, we can use that.

function onButtonClick()
    script.Parent.Parent.Visible = false
    script.Parent.Parent.Parent.PacksFrame.Visible = true
    script.Parent.Parent.Parent.StoreFrame.Visible = false
    script.Parent.Parent.Parent.PlayFrame.Visible = false
    script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Workspace
.ClickSound:Play() -- IsPlaying can only be read, you can't change it.
    script.Parent.Parent.Parent.Parent.NowViewing.Text = "Now Viewing: Packs"
end

script.Parent.MouseButton1Click:connect(onButtonClick)

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