How to add cooldown

if input.KeyCode == Enum.KeyCode.F then
      -- do something
end

How do i make it so players arent able to spam the F keycode?

1 Like

You can just introduce a debounce variable and a cooldown. If the player inputs the letter, the script will check if the debounce is false before it gets set to true. After that, you can use wait() or task.wait() for the cooldown, until the debounce variable gets set back to false again.

pretty common code structure for cooldown is

local cd = false

UIS.InputBegan -- event stuff
if input.KeyCode == Enum.KeyCode.F and not cd then
      cd = true
      -- do something

      task.wait(1)
      cd = false
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.