How to make a click cooldown

Hello,
so I am trying to add a “cooldown” to my script that applies if you click the npc but I dont know how to do it


this is my code
I think I could use debounce but I dont know how to use it right.

so if you can it would be cool if you can help me
Have a nice day.

2 Likes
local debounce = false

ClickDetector.MouseClick:Connect(function()
   if debounce then return end
   debounce = true
   --your code
   task.wait(cooldown length)
   debounce = false
end
3 Likes

add

local debounce = false -- debounce is false right now

then add this under ClickDetector.MouseClick:Connect(function().

if debounce == false then -- if debounce is true it wont go further
debounce = true

and then add this at the end of the script.

debounce = false -- it sets debounce to false again so the script can work again

and then you need to write end at the end of the script. it should be over end)
like this:

         end
     end
end)
1 Like