I need help applying my animation to NPC

So I made a script where the animation of the NPC will begin playing.
but the problem is that animation is not working. Can someone please help me with this?
I tried putting the animation inside the script and changed some variables but the animation still isn’t working.
The animation script is in a much bigger script and is also a starterplayer script. The whole script is working fine other than the line with the animation itself.

Here is the script for the animation

local Ranger = workspace.Areas.Area2.RangerNPCs.RangerNPC1
Ranger.Humanoid:LoadAnimation(script.Anim):Play()

I sure that you need to create other var for the loadanimation.
It will be like
local anim = Ranger.Humanoid:LoadAnimation(script.Anim)
anim:Play()

but roblox did update and it’s deprecated. So you will need to use
local anim = Ranger.Humanoid:WaitForChild(“Animator”):LoadAnimation(script.Anim)
anim:Play()

I tried exporting the current animation playing in my animation editor then copied the animation ID, when I used that ID, the animation finally started playing after many attempts.

But thank you for giving suggestions to the problem :slightly_smiling_face: