Animations won't play on an NPC

I’m trying to play animations on an NPC but it won’t work.

Server Script:

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507766388"
NewNPC:FindFirstChildOfClass("Humanoid"):LoadAnimation(animation):Play()

Error:
image

NPC:
image

Why do you have an AnimationController? Isnt that an Animator for Non Humanoid objects?

Because I need to put an Animator in the Humanoid or an AnimationController!

image

under Humanoid OR AnimationController

Yes, but it still won’t work even if I put the animator under the humanoid…

image

-- local animation = Instance.new("Animation") -- What i would do is just create an animation object inside the rig or somewhere else, but for this situation i will assume its outside the rig
-- I don't know where the NPC is so i will asume its in workspace
local anim = workspace:FindFirstChild("NPCAnim")
local npc = workspace:FindFirstChild("DefaultNPC"):FindFirstChildOfClass("Humanoid")
local loadedAnim = npc:LoadAnimation(anim)
loadedAnim:Play()

I’ve tested it an it worked! :slight_smile:

I tried to use this script and it didn’t work!
image

local Humanoid = NewNPC.Humanoid
local anim = game.ReplicatedStorage.Animations.NPCAnimations.Stand
local loadedAnim = Humanoid:LoadAnimation(anim)
loadedAnim:Play()

I think you should use rbxasset:// instead of the url.

Alright, first off you shouldn’t be using

Humanoid:LoadAnimation()

as it’s being deprecated, place an “Animator” below your NPC’s Humanoid either manually or through the script.

In your script:

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/asset/?id=507766388"
NewNPC:FindFirstChildOfClass("Humanoid"):LoadAnimation(animation):Play()

You’re creating a new animation, but don’t appear to be parenting it to anything. You can either parent it by doing:

local animation = Instance.new("Animation",NewNPC:WaitForChild("Humanoid"))

--Or

local animation = Instance.new("Animation")
animation.Parent = NewNPC:WaitForChild("Humanoid")

We then want to load the animation to the animator which we can do the same way as loading it to the humanoid.

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507766388"
animation.Parent = NewNPC:WaitForChild("Humanoid")

local loadedAnimation = NewNPC.Humanoid:WaitForChild("Animator"):LoadAnimation(animation)

We can then go ahead and play the animation just like you always would.

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507766388"
animation.Parent = NewNPC:WaitForChild("Humanoid")

local loadedAnimation = NewNPC.Humanoid:WaitForChild("Animator"):LoadAnimation(animation)

loadedAnimation:Play()

Ensure that your NPC is referenced correctly in your script. This will also just play the animation as soon as the script runs, but you can remove the loadedAnimation:Play() and place it wherever in your script to trigger the animation on the NPC.

I’ve setup my script and NPC to match yours in a game, to ensure functionality. If this script isn’t working for you you’ve done something wrong, and i’ll be glad to help you get the issue fixed.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.