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

How do I debounce my click detector?

Asked by 4 years ago
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()
0
I need a debouce so that people cannot spam Alpha_Imperial 5 — 4y
0
this question was answered via chat by the way, so dont reply. @everybody TurboBOV 15 — 4y
0
I tried your script, there is no error, why did you write this question. The debounce works, doesn't it??? Eternalove_fan32 188 — 4y
0
Ah, I'm sorry, I didn't see the script any better. Eternalove_fan32 188 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

Answer this question