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

can someone help me add a cooldown on this animation script?

Asked by 3 years ago

its a simple script from a YT vid, i cant figure out how to add a cooldown to make it so you cant play the animation again until the cooldown ends

local Tool = script.Parent
local Animation = Tool.Animation

Tool.Activated:Connect(function()
    local Character = Tool.Parent
    local Humanoid = Character.Humanoid

    local AnimationTrack = Humanoid:LoadAnimation(Animation)
    AnimationTrack:Play()
end)

incase if its not clear, im not the best at scripting

2 answers

Log in to vote
3
Answered by
7777ert 49
3 years ago

Using debounce would be a good idea when making cooldowns:

local Tool = script.Parent
local Animation = Tool.Animation
local debounce = false

Tool.Activated:Connect(function()
    if not debounce then
        debounce = true
            local Character = Tool.Parent
            local Humanoid = Character.Humanoid

            local AnimationTrack = Humanoid:LoadAnimation(Animation)
            AnimationTrack:Play()

        wait(5) -- change cooldown time
        debounce = false
    end
end)

In this script, a variable debounce was added (you can change the variable name if you want to). It was false at first. When you activated the tool, it will check if debounce is false. If yes, if will turn debounce to true and run the animation. Then it will wait until it finished cooling down and turn it to false again.

0
^^ Kudos Omq_ItzJasmin 666 — 3y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

To cooldown use a debounce, Debounce is used as a bool value variable, You can change the name to cooldown or something, It's your choice, If you need a example try this

local Tool = script.Parent
local Animation = Tool.Animation
local deboune = false

Tool.Activated:Connect(function()
    if debounce == false the

         local Character = Tool.Parent
         local Humanoid = Character.Humanoid

         local AnimationTrack = Humanoid:LoadAnimation(Animation)
         AnimationTrack:Play()

        wait(3) -- Colodwn time
        debounce = false
    end
end)

Answer this question