For my game, being hit causes your character to “flinch” and an animation plays showing this. Hit particles and sounds also play but when the client (or server) plays this animation, by the time it replicates it is not in sync with the sound/particles at all so I thought of a nice solution:
•Have each client load and play the flinch animation right when the effects are played, so there is an insanely low amount of delay (<0.002 seconds benchmarked)
My issue is that each client playing it, when the client that is hit plays it, it replicates and on their screen it will look smooth and everything but for other clients the animation double plays causing a very unsightly result.
I’ve tried the following methods to have this one animation played on the character not auto-replicate:
•Create another Animator object on the client that it loads to if its hit
•Create an AnimationController on the client that it loads to if hit
This does fix the issue but at a detrimental cost, no other animations play on their character on their screen. If anyone knows any potential solutions to this, I’d appreciate you greatly.
(i know i probably explained and asked some of this badly so ask anything necessary)
This is an interesting problem. Perhaps instead of destroying the server animator, you could reparent it to something like Replicated Storage, make the client animator for the hit, play the animation, destroy the client animator, and then reparent the server one from replicated storage back to the humanoid? All of this being done on the client where the animation is being played.
The last parented animator is the one that handles all the animations, this method makes me unable to have players being hit frequently which is too much of a downside due to the multiplayer nature.
I’ve still been trying various minor modifications to my listed attempts to no success, that being:
Parenting the original Animator to ReplicatedStorage, creating and playing on a new locally created one, then moving the old Animator object back into the humanoid
If anyone knows a workaround, I’d appreciate any help so much!
Hey it’s been a few years but I came across the same issue and found a solution through another post. Here’s the link in case you’re still wondering about the solution or if someone else experiences the same issue: Stopping an Animations Auto-Replication - #2 by DEVLocalPlayer
Although since Humanoid.AnimationPlayed is deprecated now use Animator.AnimationPlayed instead.
The solution being:
Connect original animator .AnimationPlayed event to a function that checks the AnimationTrack.Animation.AnimationId of the passed track, stopping the animation immediately with :Stop(0) if the AnimationId matches the ID of the animation you don’t want to replicate and the local player is not the one that owns the animator.
Check on every client before playing the animation you don’t want the replicate:
If the player is the original client,
load the animation onto the player’s animator and play as usual
If the player is a different client,
Parent the original animator to an AnimationController instance in ReplicatedStorage
Create a new animator, loading and playing the animation you don’t want to replicate on that