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

How do I stop a custom looping animation once the tool is unequiped?

Asked by 6 years ago
Edited 6 years ago

Hello scriptinghelpers! I am currently making a roleplay game, there is a problem with the script inside the sword I am making, I have an idle animation set to loop, but the problem is when the sword is unequiped the animation continues playing, even when I try to equip tools that do not have an animation yet the idle animation from the sword will not stop playing.

Here is the script I am using to load the animations:

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)

Answer this question