Where to play an animation, client or server?

*** I see this post linked to a lot, so I thought I would add one little bit of information :
If you try to replace default animations (walk, run, idle, swim, etc…) and you use the same animation for 2 or more states (such as using the same animation for walking and running) you will get strange issues where sometimes the animations play and sometimes they do not, ALWAYS use a unique animation ID for each animation, even if that means publishing one animation twice to get 2 different ID’s ***

Original Post ***
If I have a diving board in my game, and when a player steps to the end, a server script gives them a jump velocity, and plays a random diving animation.

Should the server script send a message to the client, telling it which animation to play, since the player is client controlled, rather than an npc?

Also, will the animation replicate to other clients, in other words, will they, as bystanders see you do the crazy dive animation, or do I need to do anything special for that to happen?

Should I stop animations from being played on the character that is diving, before playing the dive animation, or should I simply play the dive animation at the highest priority?

Thanks.

4 Likes

Animations for players should be played on the client and will replicate, and I recommend putting it on highest priority

16 Likes

I recommend using a script in the Server Script Service that gives to player a jump Velocity and then it plays an animation. It’s the only way and if you use this method, you will see other players play an animation.

If you use a Local Script it will only work on a client and only that client will see that animation, while looking at other players, you won’t see their animation… I hope this helped.

2 Likes

For player owned characters you need to use a localscript (will replicate) for NPCs a serverscript

(From the old Roblox wiki)
“Just remember that if your model is intended for a player character, the animation must be loaded into a Humanoid and run with a LocalScript. If the model is for a NPC, then it should be loaded into an AnimationController and run with a server Script”

5 Likes

Placing a Local Script in StarterPlayer>StarterCharacterScripts should work.

EDIT: I tried using custom attack animation local script inside of StarterCharacterScripts and it works if you are playing with more players in-game!

You are typically encouraged to entrust the running of animations to the client. This is because they have network ownership over their character, so animations can reasonably replicate as they operate on Motor6Ds in the character and performance is relatively smooth. There isn’t any inherent harm in running an animation on the server. I’d say this kind of scenario is purely preferential or what seems to work better for your case.

Set the diving animation to the highest priority. If I recall correctly, all Roblox animations use the Core priority with some (such as jump) use idle. None of them use Movement or Action.

10 Likes

Thanks everyone for the answers. They really help.

I would like to run it in local script too, but I prefer server script because cheaters can read local script code