Syncing animations perfectly across the network

Heyo everyone.

Terminology:

  • Initiate client: the client that initiated the sync
  • Target client: the client that the initiate client wants to sync with
  • other client: any client that is not the initiate client

I have recently ran into quite an issue trying to get the animations of two players to sync perfectly across the network. Whatever solution I come up with or people have come up with in the past for animation syncing either has the initiate client see an imperfect sync or has all other clients see an imperfect sync.

Solutions that I have attempted so far have all failed, the main two being:

  • When a sync is initiated, the server will sync the animations of the initiate client to the time positions of the target client. This is for some reason off for anyone but the initiate client.
  • When a sync is initiated, the server will tell all other clients to sync the animations of the initiate client to the time positions of the target client. This is perfect for anyone but the initiate client.

I am quite new to Roblox development, and the reason all this is not working is probably the way animations replicate, but I just have no idea anymore, so if anyone has an idea or a system that perfectly syncs animations across the whole network for everyone, please let me know.

I have wasted so much time on this so at this point I don’t mind being spoonfed if there is a fully worked up solution I don’t mind it being thrown at me.

1 Like

RemoteEvents will do the trick.

Do you have a demonstration of what you mean, because I was using remote events in both the examples I mentioned above with no success.

Have the animations play on the server and have local scripts trigger those animations.

As I said here I unfortunately tried this already, the client that wants to sync fires a remote event which the server then listens to and executes the sync, this does make the two characters play the same animation but it does not sync them perfectly, there is a noticeable delay between the two animations.

There will always be a slight delay, this is inevitable because of latency. You could force a delay in an attempt to try and resync both characters.

Would you know how a game like Vibe NYC goes about this, they seem to have ms perfect animation sync.

Or maybe is there a way to stop certain animations from replicating from client to server, because if this was possible then I could have all clients completely control everyone’s animations, and not worry about having to account for the time it took an animation to replicate.

If you want to sync animations with someone on all clients, then you should have a local system that handles all dancing animations (for both you and all other players). If you decide you want to change your animation, not only should you play the animation locally, but you should also inform the other clients that you changed your animation. You would do this by first firing a remote event from the client to the server, and then firing another from the server to all other clients.

Now, hopefully this generally makes sense but there’s a few technical things that you should be aware of. Specifically, if you decide to sync with someone you shouldn’t be informing other clients of any animation updates. Instead, whenever the other clients receive an animation update from the player you are syncing with, and inevitably call a function along the lines of :SetAnimation() for the player you’re syncing with, this function should in turn check to see if anyone is syncing with them, and if they are then it should at the same time call this :SetAnimation() function for whoever is syncing with them as well. You will want to put this logic into the :SetAnimation() function, otherwise if other players are syncing onto you, then they won’t receive any updated animations should the person you are syncing with decide to change up their animations.

Additionally, whenever you first decide to sync with someone, you should not only play the animation they are playing (if applicable), but it should also set the .TimePosition property of the AnimationTrack to match theirs. See: AnimationTrack | Roblox Creator Documentation

Side note, if you want to stop certain animations from playing, you can detect when a new AnimationTrack begins playing for any player by using the .AnimationPlayed event of their Humanoid. You can then detect if the AnimationTrack that begins playing is one that you would like to not be played, and then subsequently if it is, you can stop it.

3 Likes

Thank you for the detailed response, I’ll take a shot at implementing this as soon as possible, and mark this as the solution if it works!

I believe I am either doing something wrong or running into an issue. I cannot stop the replication of an animation from one client to the other clients, even though I am stopping and destroying the track on the server when an animation is played.

I have it set up that:

  • When a player starts an animation, it informs the server, which informs all other clients, which play the same animation on the correct animator.
  • When a player stops an animation, it informs the server, which informs all other clients, which stop the same animation on the correct animator.
  • When a player syncs with another, it informs the server, which informs all other clients, which get the current time position of the targets track and load the animation onto the correct animator and set the time position to match.

Everything works perfectly, except of course the animation syncing, which is still off. I tried it two different ways:

  • one where the player that initiated the sync sets their own time position to match and then notifies the server, which notifies all clients except the initiate client -|- this is perfectly synced for the initiate client but is off for other clients.
  • the other being where the player that initiated the sync does not set their own time position, but instead only notified the server, which notifies all clients except the initiate client -|- this is perfectly synced for all clients, except the initiate client which is not playing an animation at all since it never started syncing, it only updated the server.

This leads be to believe that the only problem is the fact that I cannot stop the animation from replicating. How do I go about this?

Anyone know where to go from here, or how this could be done?

I have a weird issue with my sync and I need help

I have a little bit of knowledge from all the research I had to do. You need to be more specific about the issue when you ask though, otherwise I am not sure if I can actually help you.

The problem I have if glitched Animations on sync
robloxapp-20220420-1231271.wmv (2.6 MB)

I know I might be very late, but in order to fix this just handle all animations on the server. At least it worked for me.

Always use task.wait() in your scripts, not wait(). This will directly impact lag like this in many cases. I understand that isn’t part of your animations but it can be part of what’s going on overall.

Edit: lol, a year old. My bad.

Hey OP! did you ever find a solution to this problem, I understand I’m two years late to respond; but I’m still curious because I found myself with the same problem with syncing animations.

There’s a way to stop animation from replicating by creating a new animator and setting the original animator to an AnimationController in replicated storage. Do this from the client and the server will not replicate animation because a newly created animator from the client will not exist on the server.

What I recommend is firing the server, passing through Workspace:GetServerTimeNow() and calculating the delay time between client - server, then firing both clients to start playing their animations with, again, the time, subtract it and adjust the track that amount of seconds into the future.

Thank you so much this helped me out alot I thought wait() was enough