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

Make sword strike animation wait untill the animation is done before allowing it to play agaom?

Asked by 6 years ago

I need help. When I click my mouse it plays the animation, but if I keep clicking it repeats it. How could I make it wait for the animation to play before being able to play again? This is what I have so far. Thanks.

local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = nil

Tool.Activated:connect(function()
    animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
    animTrack:Play()    
end)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)

Tool.Activated:connect(function()
    if animTrack.IsPlaying == false then
        animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
        animTrack:Play()
    end
end)
Ad
Log in to vote
0
Answered by 6 years ago

Here is the script;

local animation = script.Parent.Animation
local Tool = script.Parent
local animTrack = script.Parent.Parent.Humanoid:LoadAnimation(animation)
local canplay = true

Tool.Activated:connect(function()
    if canplay then
        canplay = false
        animTrack:Play()
        animTrack.Stopped:wait()
        canplay = true
    end
end)

canplay is a bool value, and a debouncer. If you do not know what a debouncer is then I would suggest looking it up on YouTube.

Answer this question