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

How do I stop a sound after a ClickDetector plays the sound?

Asked by 4 years ago

I am working on making a tv show for my model TV in one of my games. What I want to do is that if you click the block again, it turns off the sound and when you click it, then it would play the sound again. I could not find any videos. Code is below.

Brick = script.Parent
Sound = Brick.Show

function onClicked()
    Sound:Play()
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
-1
Answered by
0_2k 496 Moderation Voter
4 years ago
Edited 4 years ago

Here's my way to do this, as I don't like using functions that way

local sound = script.Parent.Show
local a = 1

script.Parent.ClickDetector.MouseClick:Connect(function()
    if a == 1 then
        sound:Play()
        a = 2
    elseif a== 2 then
        sound:Stop()
        a = 1
    end
end

local sound = script.Parent.Show local bool = false script.Parent.ClickDetector.MouseClick:Connect(function() bool = not bool if not bool then sound:Play() else sound:Stop() end end
0
Um why use number instead of Boolean? 123nabilben123 499 — 4y
0
You could also, this was just a better example if you're more on the new end. 0_2k 496 — 4y
Ad

Answer this question