I tried making an animation for my tool and it worked. But, I want to make it so that is has a 5 seconds cooldown.. help pls
script.Parent.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) animation:Play() end) end) script.Parent.Unequipped:Connect(function() animation:Stop() end)
For that, you should use debounce! It's quite a simple concept firstly you want to create a variable call it debounce or cooldown anything really! And make the variable false. I'm not too sure about what you are asking, if you are trying to achieve a cooldown on your equip/unequip or just animation from what I understand you are asking for animation so here are the building blocks.
local cooldown = false local cooldownTime = 5 -- cooldown seconds script.Parent.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() if cooldown == false then -- checks if its not on cooldown cooldown = true -- sets to cooldown animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) animation:Play() elseif cooldown == true then -- if its on cooldown it waits cooldownTime and sets false wait(cooldownTime) cooldown = false end end) end) script.Parent.Unequipped:Connect(function() animation:Stop() end)
Questions concerns and bugs, just comment!