I’m working on an ammo system for many of my ranged weapons and I’m wondering if I should consider handling ammo on the server. The reason why I’m asking if I should is simply because of hackers. I don’t want hackers to simply make it so it has more ammo than it should.
(Btw, if anyone is wondering, ammo will be attributes.)
You can have a Module with the gun’s stats such as its clip size and maximum ammo held. Then the server and client can both read this data.
To keep it server authoritative, have the client send a request to shoot a bullet and to subtract one from their local bullet count, and then on the server check if they have enough ammo and preform the shot if so and then also subtract one from the server’s bullet count.
By sharing the gun’s stats to the client and the server you can allow the client to visually see how much ammo they have and then let the server validate their ammo count too. Both the server and client know when they need to reload, but actions such as shooting can only actually be done if the server’s ammo count is above 0. If the client cheats and sets their count to 9999 it will do nothing except visually change how much ammo they have on their own client.
Have a local script contain the gun firing functionality (Which in my case, just firing a remote event containing the player’s mouse) and have it subtract a single ammo.
Then on the server script, sanity check if they have enough ammo to shoot the gun and subtract a single ammo on the server.
That seems to be alright, especially when I’m going to use attributes for the ammo as attributes won’t replicate in the server, right?