How to set a cooldown when clicking a key

Hello,

I am currently trying to make an event start when i click a key.

I have tried looking up other scripts, i tested them, but non of them work.
image

If someone could help me i would really appreciate, i have been trying for almost an hour.

KeyDown is deprecated, use the UserInputService version of it (.InputBegan)

Anyway, use a debounce to make a cooldown

local UIS = game:GetService("UserInputService")
local debounce = false

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		if debounce then return end
		debounce = true
		event:FireServer(12)
		wait()-- add a number
		debounce = false
	end
end)
1 Like

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