Is passing values from client to server safe?

Is this safe to do because I have read that passing values from the client to server is bad due to cheating but I have seen a few people also doing it, so I don’t know to avoid it or not.

Thanks :slight_smile:

Hi, with your code above, the client can set any movement speed on the server that he wants, so if the client would cheat, he could set any movement speed that he wants.

Generally speaking for game relevant things I find it a good way to see the client only as keyboard plus monitor but no logic (player input that is directly relayed to the server and then the client watches through the monitor what the server does, but the client doesn’t execute any game relevant code, only cosmetic things. For example if the player would shoot a weapon, then the client could directly spawn the sound and particle systems, maybe even a bullet so that the player has direct response but all game relevant things like the damage should happen on the server).

1 Like

Hey, thanks for the replay! really appreciate it. I thought that would be a unsafe way to replicate thats why I came here to ask. What would be a the safe way to do this then?

Thanks :slight_smile:

What would be a the safe way to do
this then?

Let the server handle everything game relevant. The only time the client needs to do something game relevant is replicating the player input (for example from keyboard, mouse) to the server.

For example if the client wants to sprint (keyboard input), then you sent to the server that the client wants to sprint. The server then does some checks (e. g. check that the character has enough stamina for sprinting) and then starts sprinting (so changes the movement speed and whatever else you want to do there like decreasing stamina and tells the other clients about it). To keep the feeling of responsivness for the client you could/would directly change the walkspeed on the client to the sprint speed without waiting for the server, so that the player has instant response.

Now if a client tries to cheat and starts sprinting without having enough stamina, that will only happen on the client, not on the server (since the server checks that the character doesn’t have enough stamina and does nothing) and for the server and all other clients this cheating client won’t be sprinting and will still move at the same speed, so nothing has changed there and on the cheating client the position will constantly snap back to the server correction.

That’s makes sense now, let me give that a go and see what happens. Thanks for the help, appreciate it.

:slight_smile: