Hello! I would like to know can I implement a cooldowntime in my game for my code:
-- Concentrate attack anim with the right mouse click:
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Heavy attack activated")
local playAnim = humanoid:LoadAnimation(con_hit_anim)
playAnim:Play()
script.BigHitAnim:FireServer()
end
end)
end) -- End of tool touched
I would really appreciate if you could help me implement a cooldown time so that when pressing this button I have to wait 5 seconds to be able to press it again.
local Debounce = false
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton2 then
Debounce = true
print("Heavy attack activated")
local playAnim = humanoid:LoadAnimation(con_hit_anim)
playAnim:Play()
script.BigHitAnim:FireServer()
wait(5)
Debounce = false
end
end)
PS you should also add checks on the server to prevent exploiters from spamming the BigHitAnim event
-- Concentrate attack anim with the right mouse click:
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
print("Heavy attack activated")
local playAnim = humanoid:LoadAnimation(con_hit_anim)
playAnim:Play()
script.BigHitAnim:FireServer()
end
end)
end) -- End of tool touched
--this is more reliable
local Debounce = false
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if gameProccesedEvent then return end
if not Debounce and input.UserInputType == Enum.UserInputType.MouseButton2 then
Debounce = true
print("Heavy attack activated")
local playAnim = humanoid:LoadAnimation(con_hit_anim)
playAnim:Play()
script.BigHitAnim:FireServer()
wait(5)
Debounce = false
end
end)
gameProccesedEvent is being made use of so when the player is typing in chat it will not run
rather than using other options like ContextActionService