What would be the best way to replicate client movements (like HumanoidRootPart teleportation through CFrame) to the server?
In non-experimental games, my problem is that doing certain attacks in my new project need to move the character smoothly, so I use TweenService. The client sees a smooth movement, while everyone else sees the player freeze until the attack is finished. I’ve tried doing the attacks from the server, but the input lag causes the game’s overall quality to drop so much that it’s barely playable.
[I forgot to mention it, but the HumanoidRootPart is anchored during the movements in order to move through the air. Could this be the cause of the problem? I’ll edit this when I have results.]
This isn’t working out for me. It always sets the center of the character somewhere odd and the character’s rotation is messed up. I tried debugging too, it seems to be caused by the animation itself.
Replication is complicated and there is no definitive best way. Every way has compromises and which method is best depends on your use case. That being said most methods tend to boil down to similar concepts.
(Note: My use of the word animation is in the context of moving parts around manually without automatic replication, not using animation objects)
Every action the user makes should have immediate feedback client side. This feedback does not necessarily have to be the actual action though. For example with teleporting, you can play an animation or display effects immediately on the client while getting the server to do the actual teleportation. This makes the action feel instant even though there can actually be a significant but now hidden delay.
For something like an attack this approach may not be possible as the attack itself should be instant. For this it is more appropriate to play the attack animation immediately on the client, send an event to the server announcing the attack, calculate the outcome of the attack on the server (damage etc) and then replicate it to every client except the source client. This can just be telling each client to call the same function used on the source client. The timing will be different on each client but as long as two clients aren’t sitting next to each other you can’t really tell.
This does however cause another issue. Before playing the animation you need to ensure whatever the animation is being played on is in the correct state. For example the player needs to be in the correct place and facing the correct direction before the animation should be played. If you aren’t careful then subtle changes in the starting state can potentially cause clients to see very different results.
TL;DR Do both the methods you already did. Do the attack immediately on the client and use the server to replicate the attack to every other client.
If people appear laggy it means you aren’t playing the animation locally properly. On the server there should be no animation played, it should be local to every client. If you are already doing this then it most likely means something is trying to replicate over the animation, along the lines of the server saying a player is standing still but the client is also playing the animation for the client at the same time.
If the game is lagging at that rate, you should try and see if they server is doing too much work, or if the replication is happening too much. In a previous game I made, I put a lot of stress server side, and it created loads of lag.