So ,i have a script for my sword
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) script.Parent.Unequipped:Connect(function() local character = game.Players.LocalPlayer.Character local idle = character.Humanoid:LoadAnimation(script.Idle) idle:Stop() end)
basically it plays the idle animation unless the tool is activated, then it will run the attack animation and go back to the idle animation after 1 second.
HOWEVER, the problem is.. when i unequipped the sword my character model still plays the idle animation, so he pretty much runs around with his hand up but no sword in it.
idle
needs to be global across the script. Don't use LoadAnimation every time you want to play/stop it, because that would make a new animation playing on top of the other one. I might also suggest removing the code on line 6 as you don't use it in that function.
local CanAttack = true local idle = nil script.Parent.Equipped:connect(function() 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 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) script.Parent.Unequipped:Connect(function() local character = game.Players.LocalPlayer.Character idle:Stop() idle:Destroy() end)
You need to put, on unequip stop animation. Because the animation plays on equip, so the script does not have a stop point it still thinks the sword is equipped. So it is still playing the animation. When you put it in a stop point the script will know the sword is not equipped so I need to stop playing animation.