How do i play an animation in my npc

Hello i am trying to play an idle animation for my Npc. It wont seem to work. All parts of the Npc are not anchored and the Npc does have a humanoid and my animation is not corrupted and works just fine, its just the animation wont work for my Npc for some reason. I don’t know what this reason is.

Script

local animation = script:WaitForChild(“idle”)
local humanoid = script.Parent
local idle = humanoid:LoadAnimation(animation)

idle:Play()
idle.Looped = true

Gyazo Link

https://gyazo.com/aa9243ba7d298d02f71751facc2cc018

3 Likes

https://gyazo.com/87a93b6a9696dff65516d753a6ca8a9d

Here is a video I linked if you need help cause I gtg right now.https://www.youtube.com/watch?v=hSbyWsnPth0

First of all, please indent your code to make it easier to read. Also, is your animation called idle? I honestly would do
local animation = script:WaitForChild(“idle”)
I would change that to
local animation = “Npc Name here”.Character.Humanoid:LoadAnimation(animation)

I know how to use moon animator and animate, ive made many animations, just this one wont work for some reason

alright i indented my code and did it that way but it still wouldn’t work, i assume u already knew that but do u have any idea why it doesn’t?

I’d suggest just creating the animation in your script

wait(1)

local anim = Instance.new("Animation")
anim.AnimationId = "(Anim id here)"
local track
local humanoid = script.Parent
track = humanoid:LoadAnimation(anim)
track.Looped = true
trackLoopedR:Play()

And why not set the npc right next to the spawn so you don’t have to run across the map to check if the animation is working?

because the spawns are in 8 diffrent places around my map and thanks, also ive noticed that when the npc dies and respawns the animation starts playing, only once tho

  • by only once i mean the animation isnt looped

Is the animation being played on a local script or a sever script?

the animation is being played on a server script and wow fast reply!

also quick question, why do people in their scripts do, for example:
local track
-(“Text Here”)
track = “Something”
instead of defining it at the top

I don’t really know, I suggest searching up in any like, youtube vids. Or, something in this site to help you.

It doesn’t really matter I just do it out of habit.
Is the animation working now?

I found a way to make the animation work yea, i know this is very inefficient but, putting it in a while loop with a wait 5 seems to make it play

local animation = script:WaitForChild(‘Animation’)
local humanoid = script.Parent:WaitForChild(‘Humanoid’)
local dancer = humanoid:LoadAnimation(animation)

while true do
dancer:Play()


Can you try?

yea i did something like that except its

wait(1)

local animation = script:WaitForChild(“idle”)

local humanoid = script.Parent

local idle = humanoid:LoadAnimation(animation)

while true do

wait(5)

idle:Play()

end

Yep, should work. Tell me if it does not.

Hm, you sure? It should be working. Just letting this know.

yea works for me too, just going to have a decent amount of npcs so i hope this method doesnt lag my game