Trying to Pre-Load Animations

I want to Pre-Load animations because whenever I swing my sword, the first swing looks always laggy or something weird. but after that, each swing looks very smooth and good. Some Devforum said you need to pre-load you animations to prevent that from happening.

I read alot of Forums and they said this was a good way to pre-load animations.

Put a local script in ReplicatedFirst then put a Folder in it called Animations and put the animations in it, and I put in the script they gave. The animation is still laggy on the first swing

3 questions. Did I put the animations in the folder correctly? Is the Code Incorrect or something? (Doesn’t have any errors in console and seems to work), and or is there anything else I can do to fix this and do any other method to pre-load animations I can do?


Local

1 Like

I wished that that could be possible but it’s not. The only way to preload animations is to have a local script load the animations for the server. Because local scripts have easier access to the player’s avatar and stuff, so you can load them there are play them on the local script as well.

1 Like

I messed around abit and used ChatGPT (because I’m not best with scripting yet), and managed to come up with this. It even works really well

By any chance do you know if it’s possible to play animations locally BUT “display” it on the server side? So it wouldn’t put as much stress on the server compared to just playing the animation on the server?

Would that even be perfered? Assuming animations playing locally would probably be smoother looking?

1 Like

Animations are already run on both the client and the server. It’s run on the server so that part positions are correct if scripts want to access them, and run on the client to make it look smoother.

The performance impact of animations is generally going to be negligible, but they are run at a lower framerate on the client when the character they are being played on is far away/when there are too many characters.

Also, this code doesn’t seem to explicitly call ContentProvider:PreloadAsync. If it’s working fine, it might just be that loading an animation onto an Animator preloads it automatically, or that your internet is fast enough for it not to be an issue.


Minor code nitpicks:

  • You should call :LoadAnimation on the Animator object that is the child of Humanoids, not directly on the Humanoid itself, because that function is deprecated:

You just need to replace all the humanoid:LoadAnimations in your code with humanoid.Animator:LoadAnimations

  • for _, id in ipairs(animationIds) do can be shortened to for _, id in animationIds do

It should be correct, as long as the Animations folder has a bunch of Animation objects with their IDs set, and the script is a LocalScript or has it’s RunContext property set to Client.

1 Like

Thank you for the insight! All this information is very valuable to me! I have updated things and changed things according to what you’ve said!

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