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

how I can add a cooldown to this tool animation?

Asked by
2jxi 4
3 years ago

Hello! I am new to scripting, and I was wondering how I can add a cooldown to this tool animation. So I don't really want it to be spammed Thank you!

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")
local Check = 0
local Enable = true

Tool.Activated:Connect(function()
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
if Enable == true then
    Enable = false
    if Check == 0 then
        humanoid:LoadAnimation(script.Anim03):Play()
        script.Parent.Combo.C0:FireServer(script.Parent.Handle.HitPart)
        script.Swing:Play()
        wait(0.6)
        Check = 1
        Enable = true
    else if Check == 1 then
        humanoid:LoadAnimation(script.Anim04):Play()
        script.Parent.Combo.C1:FireServer(script.Parent.Handle.HitPart)
        script.Swing:Play()
        wait(0.6)
        Check = 0
        Enable = true
    end
    end
 end
end)

while wait(10) do
    if Check == 1 then
        Check = 0
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You can add another wait() function AFTER check if statements

There's not much to explain but if you want to add a cooldown to the tool then you can use the wait() function. This is THE most simple way of adding a cooldown because there's only 1 code line. I also fixed some of the code

Tool.Activated:Connect(function()
   local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
   if Enable == true then
      Enable = false
      if Check == 0 then
         humanoid:LoadAnimation(script.Anim03):Play()
        script.Parent.Combo.C0:FireServer(script.Parent.Handle.HitPart)
        script.Swing:Play()
        wait(0.6)
        Check = 1
      else if Check == 1 then
        humanoid:LoadAnimation(script.Anim04):Play()
        script.Parent.Combo.C1:FireServer(script.Parent.Handle.HitPart)
        script.Swing:Play()
        wait(0.6)
        Check = 0
      end

      wait(5) -- Add 5 seconds cooldown
      Enable = true -- Move enable to this line because it's better

    end
end)

In the future, you probably want to know many methods which can delay things such as the wait() function which is the simplest in delaying things.

Happy Scripting!

0
If you found this answer helpful then please accept this answer and possibly help others who may look for the same answer. Somone_exe 224 — 3y
Ad

Answer this question