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