Im making a chainsaw, where it plays an animation when you equip it, and it stops the animation once you unequipped it. However, the animation only stops when you click! Why is this? CODE:
tool = script.Parent anim = tool.Animation attacking = false tool.Equipped:Connect(function() local animation = tool.Parent.Humanoid:LoadAnimation(anim) animation:Play() tool.Idle:Play() tool.Activated:Connect(function() tool.Rev:Play() tool.Idle:Stop() attacking = true tool.Deactivated:Connect(function() tool.Idle:Play() tool.Rev:Stop() attacking = false tool.Unequipped:Connect(function() animation:Stop() tool.Rev:Stop() tool.Idle:Stop() end) end) end) end) tool.Handle.Touched:Connect(function(hit) if attacking == true then if hit and hit.Parent:FindFirstChild("Humanoid") then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(50) tool.Oof:Play() hit:Destroy() end end end)
This is because you are putting all of your events inside of events. You put your unequip event inside of deactivated, deactivated inside of activated, it’s confusing the script.
Separate your code like this:
tool.Equipped:Connect(function(mouse) -- run code for Equip event mouse.Button1Down:Connect(function() -- run code for Button down event end) mouse.Button1Up:Connect(function() -- run code for the Button up event end) end) tool.Unequipped:Connect(function() -- run code for the Unequip event, in a new block of code end)