Animation not playing

So I have an eating animation that I want to play when I tool is activated. But the animation is not playing. The script is a server Script inside of StarterCharacterScripts amd there are no errors in the output bar.

Code
--Animation variables
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local isRunning = false

--Tool variables
local Tool = game.ReplicatedStorage.Food["Cake slice"]
local HealthPoints = 100

--Code
Tool.Activated:Connect(function()
if not isRunning and not HealthPoints == 0 then
isRunning = true
Animation:Play()
else
isRunning = false
Animation:Stop()
HealthPoints = HealthPoints - 10
end
end)

Only local scripts will run in StarterPlayer

Shouldn’t it be:

 if isRunning == false

I think I just figured it out. testing it right now.

local scripts can run inside a player’s character so it will work

That’s what I’m saying, only client scripts will execute when placed in any StarterPlayer folder

Same thing as if not isRunning then

if not isRunning then

is the same as

if isRunning == false then

Oh sorry I just tested that out and it is the same also might want to edit what you said right there

Not fixed.

I added
wait(1)
--after
Animation:Play()
--and removed
else

By the way using LoadAnimation on Humanoid is deprecated, for new work use Animator:LoadAnimation()

Like this?

local Animation = Humanoid.Animator:LoadAnimation(script:WaitForChild("Animation"))

Close, but it’s more efficient to check if the child actually exists first.

(from documentation)

local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
    local animationTrack = animator:LoadAnimation(animation)
	animationTrack:Play()
end