Loaded Animation Track in server returns Nil in Client?

I have a Client and Server script. When the Client script needs to play an animation, it fires an event to the Server. And Server plays it. My system:

local function playAnim(plr, hum, animation, status)
   if status == "Load" then
      local loaded = hum.Animator:LoadAnimation(animation)
      print(loaded) -- Important
      return loaded
   elseif status == "Play" then
      animation:Play() 
   end
end

So, when the status is Load, the parameter “animation” is an unloaded animation, when the status is Play, the parameter “animation” is a loaded animation track.
At print(loaded), it prints the track but in the client, it returns as “nil”. So I can’t play track anywhere. Why does it happen? How can I fix that?

Thanks for reading.

1 Like

I thought the anim should be loaded directly in the humanoid, like:

local 2play = hum:LoadAnimation(animation)
2play:Play()

Yeah, it loads at “Load” and returns the loaded animation to the client, then when the “Play” happens, Client sends that loaded track.

oh you mean Loading, it doesnt change anything ive tried all of the functions. there is a problem with server - client connection

Guys I tried with the remote function but the same thing, Client Script can’t see the animation track that loaded in a server script, I don’t know why does it happen.

AnimationTracks don’t functions like other instances. You cannot parent them to workspace or even to ReplicatedStorage.

That means that they won’t get replicated. It’s quite annoying but ig thats how Roblox works :man_shrugging:t6:

This code will give an error.

local Animation: Animation = -- Reference animation
local AnimationTrack: AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack.Parent = Animator
AnimationTrack:Play()

Also for some reason you can do things like this

local AnimatrionTrack: AnimationTrack = Animator:LoadAnimiation(Animation)
AnimationTrack:Play()
AnimationTrack:Destroy()
wait(4) -- Notice how the animation still is playing even though there is not reference for it.
local AnimationTracks: {AnimationTrack} = Animator:GetPlayingAnimationTracks()
AnimationsTracks[1]:Stop()

That said. I believe you can get animation tracks from a different script simply by using this method
Animator:GetPlayingAnimationTracks()

One final thing: Humanoid:LoadAnimation is deprecated. Roblox recommends not using it.

3 Likes

But I didn’t parent the track I’ve loaded in Humanoid and return it to the Client, for a reason it can’t detect the animation like it is something in ServerStorage or ServerScriptService

For something to be replicated to the client it has to have a parent of either ReplicatedStorage, ReplicatedFirst, workspace, SoundService, Lighting or Players. (I believe there are probably some more services out there.) Since AnimationTracks can’t be assigned a parent it is impossible to pass the animationtrack the normal way as it isn’t replicated to the client.

It’s basically the same thing as passing something with a parent of ServerStorage to the client. It will always turn up nil.

6 Likes

So I’ll animate from the Client since it works, thank you very much. Also, I’ve researched it, playing animations on Client is recommended. (For those who will live this problem in future)

3 Likes

for who will have this problem on the future there is a problem when you load and play an animation on the client then you try to adjust that track on the client (speed, weight) it wont be updated on the server