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
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.
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)