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

How to stop animation when tool is unequipped?

Asked by 4 years ago
Edited 4 years ago

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.)

01local Tool = script.Parent
02local Animation = Tool.Animation
03 
04Tool.Equipped:Connect(function()
05    local Player = Tool.Parent
06    local Humanoid = Player.Humanoid
07 
08    local AnimationPlay= Humanoid:LoadAnimation(Animation)
09    AnimationPlay:Play()
10 
11end)
12 
13 
14Tool.Unequipped:Connect(function()
15 
View all 22 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question