How do I make a click button for it to play a one time sound?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a click button that when a player clicks it, the player hears a sound, but if the player smashes the button, the button doesn’t work after a few seconds and doesn’t play a sound.

  2. What is the issue? The issue is that, when you click the button, a sound plays but if you smash it with clicks, it plays the sound as many times as you click the button and I don’t want that.

  3. What solutions have you tried so far? I’ve looked for tutorials, and in the forum but there’s nothing. I don’t have very good scripting skills.

This is my first post btw, and I would appreciate it if someone helps me!

You need to add a debounce to the script which is essentially a cooldown

2 Likes

If there is a problem with this code it’s probably cause im on mobile rn

local debounce = false

    clickdetector.mouseclick:connect(function()

if debounce == false then

—your code

debounce = true

wait(—[[wait time]])

 debounce = false

end
end)
1 Like

removed for reasons (lol limitttttttttttt)

2 Likes

I’ll try it! Thank you so much!

I will also try it! Thank you so much!

Internal screaming The first thing I’m gonna say is why do you have so much “D1/D2/D3” things? Anyways

You can put this instead when it first fires:

local FireOnce = false
local Sound = workspace.SoundSomething

function onClicked()
    if FireOnce == false then
        FireOnce = true
        Sound:Play()
    end
    --Other lines of code here
end

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

I do actually recommend looking at how TweenService works, as you can really smoothly adjust the properties of BaseParts well

I’ll check it out. The door works by disabling and abling collide and transparecy so it gives an effect of real working door/gate

Oh yeah well, the other script that I sent wasn’t the one where I should have put your script but anyways, here it is the truly one. Don’t know what line to put it

Try:

Brick = script.Parent
Sound = Brick.Sound
local Debounce = false

script.Parent.ClickDetector.MouseClick:Connect(function()
if Debounce == false then
Debounce = true
Sound:Play()
wait(seconds here)
Debounce = false
end
end)

Might be some spelling errors due to me typing this on mobile

1 Like

This one worked! Thank you :hugs:

1 Like