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
01 | local Tool = script.Parent |
02 | local Animation = Tool.Animation |
03 |
04 | Tool.Activated:Connect( function () |
05 | local Character = Tool.Parent |
06 | local Humanoid = Character.Humanoid |
07 |
08 | local AnimationTrack = Humanoid:LoadAnimation(Animation) |
09 | AnimationTrack:Play() |
10 | end ) |
incase if its not clear, im not the best at scripting
Using debounce
would be a good idea when making cooldowns:
01 | local Tool = script.Parent |
02 | local Animation = Tool.Animation |
03 | local debounce = false |
04 |
05 | Tool.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 |
17 | 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.
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
01 | local Tool = script.Parent |
02 | local Animation = Tool.Animation |
03 | local deboune = false |
04 |
05 | Tool.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 |
17 | end ) |