I made an eating animation for my food tool but my code doesn’t work. I’ve tried numerous solutions but they all do not work.
This is my current code:
local EatAnimation = script.Parent.Animation
local tool = script.Parent
local anim = nil
tool.Activated:Connect(function()
print("activated")
local hum = script.Parent.Parent.Humanoid
local anim = hum:LoadAnimation(EatAnimation)
anim:Play()
end)
tool.Unequipped:Connect(function()
if anim then
anim:Stop()
end
end)
You’re wanting to wait for the Humanoid’s Animator to load, not the animation. Unless the animation is being instanced into the game, it should already be an object. (albeit with 0 practical use other than to stop other animations until it does load)
local Animation = script.Parent:WaitForChild("Animation")
local Tool = script.Parent
local LoadedAnimation = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
Tool.Activated:Connect(function()
LoadedAnimation:Play()
end)
Tool.Unequipped:Connect(function()
if (LoadedAnimation.IsPlaying) then
LoadedAnimation:Stop()
end
end)