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

Why isn't my animation stopping once I unequipped the tool?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

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)


1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
0
Still won't work. Plus, it's a sound and not an animation Mr_Unlucky 1085 — 5y
0
I edited the answer. User#19524 175 — 5y
0
thanks! Mr_Unlucky 1085 — 5y
Ad

Answer this question