Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

3 comments

0

Still won't work. Plus, it's a sound and not an animation

0

I edited the answer.

0

thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.