How would I Load an animation into a Humanoid created ClientSided

I’m working with Viewport frames and I need to Load an Animation into a NPC Cloned from lighting using a Local script

I’m a little confused on the limitations of loading an animation to a humanoid. because I keep getting error messages saying I cant load animation from script etc.

So in summery I need to clone a NPC from lighting (In ClientSide) and load/play an animation to that NPC using any means.

What ive tried:

  1. A script in the NPC that has a OnChanged function connected to a value inside the NPC. And that function will then load and play the animation. But it doesn’t fire because its a server sided script and the Value is changed in a local script.

  2. Load and play the animation while the NPC is in Lighting. and then have the local script Clone it for the ViewportFrame. But this doesnt work either.

as you can probably tell I’m not very confident with Coding animations :stuck_out_tongue:

Thanks for reading ~ Anon

2 Likes

First thing’s first, do not load an animation to the humanoid, it’s deprecated. Create an animator and place it inside of the humanoid, use that animator to control animations.

Second thing, you can load animations on the client similarly to how you’d load an animation on the client. You need an animation instance whose AnimationId is present, then you use this animation instance to create an AnimationTrack which can be played.

local animation = script.Parent.Animation

local humanoid = script.Parent:WaitForChild('Humanoid')
local animator = humanoid:FindFirstChild('Humanoid') or Instance.new('Animator')
animator.Parent = humanoid -- just in case the animator didn't exist, we want to parent it to the humanoid

local animationTrack = animator:LoadAnimation(animation) -- this will return an AnimationTrack instance that can be played

animationTrack:Play()
2 Likes

I still cant get it to work,

I’m not saying what you’ve sent is wrong. I just cant work it out

The script that plays the animation for the NPC when in the NPC, doesn’t run at all even when the NPC has been placed out of lighting. I put print(“Print If Running”) and it never does

and when trying to play animation from the client sided script (in a Player GUI). nothing happens.

use RemoteFunction:InvokeServer(rig), it will only show to the client too because the rig is duplicated for each client[s]

1 Like

If you want to play animations inside a ViewportFrame, make sure to put a WorldModel object under the ViewportFrame. All parts will be under the WorldModel object.

3 Likes

Thankyou this has fixed everything.

I probably should have learned more about viewports before making this post :stuck_out_tongue: