What I want to do is make a 3 second cool down for each time the animation plays when I left Click.
local debounce = false script.Parent.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function() if not debounce then debounce = true end print("work!") animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation) animation:Play() wait(3) debounce = false end) end) script.Parent.Unequipped:Connect(function() animation:Stop() end)
Help.
Your debounce is useless if you don't have an if
statement that restricts the event from passing through.
local debounce = true MouseButton1Click:Connect(function() if (debounce == true) then debounce = false print("Hello!") end end)
This line of code will only print "Hello!" once because right when you click, your debounce turns false
. This means when you click again it'll check if your debounce (which is false
) is true
.
In order to make it say "Hello!" again, we must make the debounce true
again. That is also where we can add wait
to prevent it from being clicked multiple times.
local debounce = true MouseButton1Click:Connect(function() if (debounce == true) then debounce = false print("Hello!") wait(3) debounce = true end end)