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

Brick Plays Sound on Click?

Asked by 3 years ago

It's hard to explain in the title, but I already know how to make a sound play when a brick is clicked, but I am struggling with the problem that if I click the brick again the sound doesn't play anymore. It's a paper rustle sound that only plays once after the brick is clicked.

This is my script (Lines 09 and 12 are relevant, line 8 is another sound object):

function onClick(click)
    for i,v in pairs (script.Parent:GetChildren()) do
        if v.ClassName == "ScreenGui" then
            c = v:Clone()
            c.Parent = click.PlayerGui
        end
    end
    game:GetService("SoundService").Sound:Destroy()
    script.Parent.paperRustle:Play()
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)
0
Give your sound a certain name not just Sound for line 8 I suggest. DogCooper 2 — 3y
0
The sound doesn't play more than once because you've already destroyed the sound inside of the SoundService, so that when the script tries to look for it again it will not find it and will throw an error at you. DeceptiveCaster 3761 — 3y
0
Alright, so what you can do is the comment above me. Just inside the script in function onClick(click) put at the bottem of it to "Disable the current script that makes the sound function work". owenm00 22 — 3y

2 answers

Log in to vote
0
Answered by
owenm00 22
3 years ago

function onClick(click) for i,v in pairs (script.Parent:GetChildren()) do if v.ClassName == "ScreenGui" then c = v:Clone() c.Parent = click.PlayerGui script.Disabled = true -- putting this inside the script should allow everything to work, but at the end it will disable the script so when the player presses the button again the script wont be there. end end game:GetService("SoundService").Sound:Destroy() script.Parent.paperRustle:Play() end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

Ad
Log in to vote
0
Answered by 3 years ago

Just realized the script won't continue to play the rustling sound if it runs into an error before then. I put the paper rustle sound at the beginning of the function to make it work each time.

Answer this question