Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

NPC animation not playing?

I have a simple animation for an NPC. There's a script in the character with and animation inside. The AnimationID of it are the numbers that come up from the animations tab on the website link.

The script goes like this:


local anim = script:WaitForChild('Animation')
local hu = script.Parent:WaitForChild("Humanoid")
local dance = hu:LoadAnimation(anim)

wait(1)

dance:Play()

But for some reason it doesn't do anything. When I put in a print after the Play()

eg:

wait(1)

dance:Play()
print('Played')

It DOES print 'Played' although I can't see it animating.

Is there a different ID I need to use for the animation? I know for gamepasses there is a different Data-Asset-ID, so is there something similar for animations too?

Please help.

4 answers

✓ Accepted answer

Actually it seems about right. Try changing script:WaitForChild("Animation") to script.Animation

Everything seems right.

Here are the things you need to check for:

  • If the NPC is anchored, unanchor it.

  • If you want the NPC to not move, even though you need the NPC unanchored, then anchor the HumanoidRootPart

  • Another way is to add this script:

script.Parent.Parent.HumanoidRootPart.Anchored = true

Hope this helps!

1 comment

0

Nothing is working... I've even tried using a different animation

The problem is that you're setting something that isn't really a variable (things like do, time, then, cannot be changed)

You can see them easily, it's highlighted in blue (unless you change the colors!)

--> Answer

Change your variable to another one, like animTrack

9 comments

0

it still doesn't do anything if i change it

0

The animation has to be yours, you have to be the one who made the animation because roblox doesnt allow you to use other people animations

0

It is mine

0

Is there an error like --> Animation ... failed to load in ...?

0

Nope...

0

Are you running it froma script or local script and where is it located?

0

Script, its in the NPC's character

0

Just like I said in the original post

0

Are you sure it doesn't play? Try another animation first (a roblox default one should be good for testing)

Try if this works:

local Animation = Instance.new('Animation')
local AnimTrack = nil 

Animation.AnimationId = "" -- paste your animation id here

AnimTrack = humanoid:LoadAnimation(Animation)
AnimTrack:Play()

Turns out that place is just broken because when I tried a different place with the EXACT SAME THINGS it worked. :/

This discussion is preserved as it was. New answers, comments, and votes are closed.