I am currently trying to make it so there is a cooldown when a player clicks a certain key. I've written out my keybind script, but was wondering how to integrate a cooldown. I've been experimenting but have been unable to fully write out the script.
local debounce = false
local cooldownTime = 1
script.Parent.Equipped:Connect(function(mouse)
mouse.KeyDown:Connect(function(key)
if not debounce and key:lower() == "r" or key:upper() == "R" then
debounce = true
local reload = game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Reload)
local sound = game:GetService("StarterPack").Pistol.reloading
reload:Play()
sound:Play()
wait(cooldownTime)
debounce = false
end
end)
end)
This is my latest variation of my original script, though I believe there may be a problem with how I applied the 'and' in my keybind section. I'm relatively new to scripting.

1 comment
Thanks alot! This on seems to work.