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 4 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

01local Tool = script.Parent
02local Animation = Tool.Animation
03 
04Tool.Activated:Connect(function()
05    local Character = Tool.Parent
06    local Humanoid = Character.Humanoid
07 
08    local AnimationTrack = Humanoid:LoadAnimation(Animation)
09    AnimationTrack:Play()
10end)

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

2 answers

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

Using debounce would be a good idea when making cooldowns:

01local Tool = script.Parent
02local Animation = Tool.Animation
03local debounce = false
04 
05Tool.Activated:Connect(function()
06    if not debounce then
07        debounce = true
08            local Character = Tool.Parent
09            local Humanoid = Character.Humanoid
10 
11            local AnimationTrack = Humanoid:LoadAnimation(Animation)
12            AnimationTrack:Play()
13 
14        wait(5) -- change cooldown time
15        debounce = false
16    end
17end)

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 — 4y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
4 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

01local Tool = script.Parent
02local Animation = Tool.Animation
03local deboune = false
04 
05Tool.Activated:Connect(function()
06    if debounce == false the
07 
08         local Character = Tool.Parent
09         local Humanoid = Character.Humanoid
10 
11         local AnimationTrack = Humanoid:LoadAnimation(Animation)
12         AnimationTrack:Play()
13 
14        wait(3) -- Colodwn time
15        debounce = false
16    end
17end)

Answer this question