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

How do i stop an animation after the tool is unequipped?

Asked by
Echtic 128
6 years ago

I made a sword which works perfectly fine with it's slashing and idle animation, but when i unequip the sword the idle animation remains active.How do i fix it?

Here is the script:

local CanAttack = true

script.Parent.Equipped:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

    idle:Play()
end)

script.Parent.Activated:connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)
if CanAttack == true then
attack:Play()
idle:Stop()
CanAttack = false
wait(1)
attack:Stop()
idle:Play()
CanAttack = true
script.Parent.CanDamage.Value = true
end
end)

2 answers

Log in to vote
0
Answered by 6 years ago

Most events have an opposite event. Tool has one too, Equipped --> Unequipped

You can simply use it and connect it to the animation

Tool.Unequipped:connect(function()
    animation:Stop()
end)

Change 'animation' with the animation you want to stop

0
I am thankful to your answer but it didn't work the situation still remains the same Echtic 128 — 6y
0
Okay, can you set the LoadAnimations on top of your script and try again? User#20388 0 — 6y
0
(not inside the equipped event User#20388 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I believe what you should do is make an unequipped function.

So:

script.Parent.Unequipped:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    idle:Stop()
end)

Or something along those lines.

0
Why would you load an animation already loaded on? (Also, I answered this already) User#20388 0 — 6y
0
I am thankful to your answer but it didn't work the situation still remains the same Echtic 128 — 6y
0
I was trying to define "idle," since the other functions had "idle" under local. Otherwise, unequipped wouldn't have known what "idle" meant. SweetNoodleSoup 14 — 6y
0
It would be better to put the loadanimations on top so you're sure both anis arethe same User#20388 0 — 6y

Answer this question