Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make audio work?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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!

Ad
Log in to vote
0
Answered by
Scriptree 125
8 years ago

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)

Answer this question