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
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.
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).