I'm making a pickaxe for my game and I want to have a idle animation that plays when the player has it equipped but i want it to stop playing when they unequip the tool. The animation plays when I equip the tool but when I unequip it the idle animation still plays and i cant get it to stop unless I reset my character. This is the script in the tool responsible for playing the idle animation. It is a local script
script.Parent.Equipped:connect(function() local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) idle:Play() end) script.Parent.Unequipped:connect(function() local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) idle:Destroy() end)
I have also tried
script.Parent.Unequipped:connect(function() local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle) idle:Stop() end)
but neither works for me and I don't see what I'm doing wrong.
You are loading two different animations into the humanoid every time you equip and unequip. In order to call :Stop() on the same animation, you need to refer to the same variable in which you loaded the animation. You could fix this by loading all of the animations in the script before equipping, and then only calling :Play() and :Stop() when you equip/unequip.
local Animation = Humanoid:LoadAnimation(Idle) Tool.Equipped:Connect(function() Animation:Play() end) Tool.Unequipped:Connect(function() Animation:Stop() end)