I got error can you help me?

I got error when i wrote this script (local)
And i get error name (Unable to cast value to object)

local Character = script.Parent
local Humanoid = Character:WaitForChild(“Humanoid”)

local AnimationObject = PATH_TO_ANIMATION
local LoadedAnimation = Humanoid:LoadAnimation(AnimationObject)

local oldHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function()
if oldHealth > Humanoid.Health then
print(“Humanoid took " … oldHealth - Humanoid.Health … " damage”)
LoadedAnimation:Play()
end
oldHealth = Humanoid.Health
end)

Don’t use _'s for directories from my experience. They complicate stuff.
change:

to

local AnimationObject = PathToAnimation

What is the PATH_TO_ANIMATION?

PATH_TO_ANIMATION this script give me another scripter and i changed it and put my animation i just took old version this script.

It gets messy with under squares. From my experience at least

I deleted PATH_TO_ANIMATION and put my animation. Example: 7835204

ohhhh where is your animation located in the explorer? ReplciatedStorage? ServerStorage? workspace? you should put the directory of where your animation is located inside the

local LoadedAnimation = Humanoid:LoadAnimation(**Here**)

a directory like game.ReplciatedStorage.AnimationName

So i need delete this (local AnimationObject = PATH_TO_ANIMATION
local LoadedAnimation = Humanoid:LoadAnimation(AnimationObject))

And put this? local LoadedAnimation = Humanoid:LoadAnimation(Here)?

How i can check where my animation. I sont use Moon Animation i use only standard animation.

There should be an animation instance though? When you create an animation it should make an animation instance. Correct me if I’m wrong. I don’t animate lol

So when you create animation and you need press Export and wait 3-4 sec then you see code animation and you copy this code and put in script or in animation Key

Sorry for my English. :frowning:

local Character = script.Parent
local Humanoid = Character:WaitForChild(“Humanoid”)

local AnimationObject = PATH_TO_ANIMATION
local LoadedAnimation = Humanoid:LoadAnimation(AnimationObject)

local oldHealth = Humanoid.Health
Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if oldHealth > Humanoid.Health then
print(“Humanoid took " … oldHealth - Humanoid.Health … " damage”)
LoadedAnimation:Play()
end

just so you know that there is nothing called Humanoid.HealthChanged

Okay ill try today thx for help. If this work i ll press Solution :slight_smile:

LoadAnimation need’s a object value, not a number. Try creating an Animation object then setting it’s id property.

local AnimationObject = Instance.new("Animation")
AnimationObject.AnimationId = "rbxassetid://YOURANIMATIONID"

https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

wow never knew that existed at all

idk why dont work ;-;

i cant see what doesn’t work, the error you made a post about doesn’t appear in the output, so what doesn’t work?

idk in output dont show me error vut it dont work ;-;