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

How to stop animation when tool is unequipped?

Im trying to make a animation play every time you equip a tool. It works when i equip it, but when i unequip it, the animation keeps on playing.

The error is:    Humanoid is not a valid member of Backpack "Players.fireyfoxninja21.Backpack" - Server - Animation:17

Can anybody help figure out why this wont work?

(I used a normal script inside of a tool, with a handle.)

local Tool = script.Parent
local Animation = Tool.Animation

Tool.Equipped:Connect(function()
	local Player = Tool.Parent
	local Humanoid = Player.Humanoid

	local AnimationPlay= Humanoid:LoadAnimation(Animation)
	AnimationPlay:Play()
	
end)


Tool.Unequipped:Connect(function()
	
	local Player = Tool.Parent
	local Humanoid = Player.Humanoid

	local AnimationPlay = Humanoid:LoadAnimation(Animation)
	
	AnimationPlay:Stop()
end)


1 answer

youre gonna want to save the loaded animation to a variable which from you can then you :Play() and :Stop() on

also, Humanoid:LoadAnimation has been deprecated which means it shouldnt be used

use humanoid.Animator:LoadAnimation instead

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