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 3 years ago
Edited 3 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.)

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

Log in to vote
0
Answered by 3 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