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)
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)
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.