local isOn = true
local debouce = false
function on()
isOn = true
script.Parent.Transparency = 0
script.Parent.CanCollide = true
end
function off()
isOn = false
script.Parent.Transparency = 0.8
script.Parent.CanCollide = false
wait(5)
script.Parent.Transparency = 0
script.Parent.CanCollide = true
end
function onClicked()
if isOn == true then off() else off() end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
on()
COMMUNITY QUESTION
How do I debounce my click detector?
1 answer
IsOn is already a debounce, there is no sense yet one to add. Debounce can also be changed, in other words IsOn is a debounce. Ok, because you want it (even if you usually only have to change your debounce to its place) I will help you:
local debounce = false
function onClicked()
if debounce == false then
script.Parent.Transparency = 0
script.Parent.CanCollide = true
wait(2.5)
debounce = true
else
script.Parent.Transparency = 0.8
script.Parent.CanCollide = false
wait(2.5)
debounce = false
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
I need a debouce so that people cannot spam
this question was answered via chat by the way, so dont reply. @everybody
I tried your script, there is no error, why did you write this question. The debounce works, doesn't it???
Ah, I'm sorry, I didn't see the script any better.