I wanted to add a cooldown to this uis the I made
I have no experience on adding a cooldown to it
here is my script:
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P then
clicks = clicks + 1 -- this detects if player clicks the input twice or more
if clicks == 1 then
--code
if click == 2 then
-- code
local db = false
UIS.InputBegan:Connect(function()
if not db then
db = true
if input.KeyCode == Enum.KeyCode.P then
clicks = clicks + 1 -- this detects if player clicks the input twice or more
if clicks == 1 then
--code
elseif clicks == 2 then
--code
end
end
game:GetService("RunService").Heartbeat:Wait() -- You can use wait() here
db = false
end
end)
Here I rewrote the piece of code, cleaned it up a little bit and added the debounce/cooldown! Hope this helps!
local db = false
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.P and db == false then
db = true
clicks = clicks + 1 -- this detects if player clicks the input twice or more
if clicks == 1 then
-- code
elseif clicks == 2 then
-- code
end
delay(1,function() -- Change the 1 to a number of your choice
db = false
end)
end
end)