How do I play an animation from serverside on an NPC

There’s this one NPC that I really want to give a walking animation, but I honestly just don’t know what the method is.

I tried giving it an animation the same way you would animate a player (this was a bad idea), and server-side I’ve never animated like that.

I tried doing:

Humanoid.Running:Connect(function()
if Humanoid.WalkSpeed > 0 then
local anim = Humanoid:LoadAnimation(AnimName)
anim:Play() -- this would error lol
end)

Little did I know this simple task was gonna be something bigger.

I’d really appreciate a different method if you know any. :v:

Put local anim = Humanoid:LoadAnimation(AnimName) outside of the event

why was it that easy bruh?? :sob::sob:

I think… :LoadAnimation returns an AnimationTrack that you can use to play the animation, I think it takes time for it to load so putting it inside the event will give an error because the AnimationTrack didn’t get loaded yet and you would a bunch of the same AnimationTracks loaded into the Humnaoid

I would actually recommend loading the animation on the Animator instead of the Humanoid as Humanoid:Load Animation() is deprecated, so it might break or error later.

Try this:

local Animator = Humanoid:FindFirstChildOfClass(“Animator”) or Instance.new(“Animator”, Humanoid)
Animator:LoadAnimation(AnimName)