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

Why is animation not stopping when unequipped?

Asked by 6 years ago

This is a very simple script that is supposed to stop an animation when I unequipped a tool. T

script.Parent.Unequipped:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation (script.Idle)
    idle:Stop()
end)

It give me an error "Humanoid is not a valid member of backpack". If thats true, then why does this work?

script.Parent.Equipped:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation (script.Idle)
    idle:Play()
end)

If you can help, that would be much appreciated.

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Once the tool is unequipped , it's moved to the Backpack, so you cannot use script.Parent.Parent to get the character (which you shouldn't be doing anyways)

local plr = game:GetService("Players").LocalPlayer

script.Parent.Unequipped:connect(function()
    local idle = plr.Character.Humanoid:LoadAnimation (script.Idle)
    idle:Stop()
end)
0
Ok. The script seems to not have an error, but the animation is not stopping now... kittonlover101 201 — 6y
0
Make sure the animation isnt looped. Galicate 106 — 6y
Ad

Answer this question