What is server authoritative code?

What is server authoritative code, and how do I use it? Broad, Ik, but if someone could point me to some resources that would be kool :sunglasses:

It just means scripts that are managed by the Server. So a ServerScript would contain server authoritative code as the client cannot access or edit the Script but the server can, while a LocalScript would be contain “client authoritative code” (idk if that’s an actual term), which can be edited by the client, but won’t affect the server directly.

1 Like

TLDR is that server authoritative is when both server and client compute some value, and when they disagree, it’s the server’s result that is used and the client result is discarded and gets synched to the server’s version. The ‘authoritative’ computer is the one whose account of things is the final truth.

Sometimes, you want to compute some value on your server, but also do the same computation on players’ clients, so that they can get the result sooner (without waiting to get the server result) so that there is no perceived lag. The authority of the scripts matters when the computations done on client and server don’t get the same result. If the computation is server authoritative, the server’s version is what gets used as the resulting game state. If it’s client authoritative, it’s the client version that wins out and the server’s result is discarded.

A common example in multiplayer games is character movement. When you move your character around, it happens immediately on your client, so that everything feels responsive. You wouldn’t want to have to wait for the server to process your input, validate it, and send it back to you before seeing your character move, as your character’s movement would then lag behind your input by your full round-trip ping to the server, plus the time it took to process the input and relay it back.

But, if the server just trusted your client completely, everyone could be fly hacking, no clipping, etc. So instead, your character’s movement is made server authoritative. The server considers your input (how your client says your avatar just moved), but it can do it’s own validation of the legality of your proposed movement and reject your client’s account of things. If the server rejects your client’s moves, it will either not move your character at all or only move it as far as it’s allowed. All other players will see the server’s version, and your client will also get this correction back from the server, and fix your character’s position on your client to match the server’s. Seeing your character snap back in time like this is commonly referred to as “rubber banding”.

This doesn’t just happen when someone’s exploiting, it also just happens normally when your client is predicting your character’s movement, but someone else’s actions invalidate it (e.g. you got stunned mid-run and have optimistically moved farther on your own client than you were able to move on the server).

1 Like