Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to add delay on animations?

Asked by 3 years ago

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)
0
When are you looking for it to cooldown? Before you unequip or during unequipped? ElBamino 153 — 3y

1 answer

Log in to vote
0
Answered by
Jo1nts 134
3 years ago

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!

0
Tested and is exactly what I wanted TYSM!!!!! :DD FokeyMouseITKRIMAAAH 7 — 3y
Ad

Answer this question