I created a gun, and it works perfectly well. Recoil, Raycasting, Ammo - everything works great!
Here is a demonstration of my gun at its current state:
I recently added a reload / ammo checking system, and a shot delay to prevent rapid spam. The problem is, I’m using remote functions to check these values, so that No Exploiters can Manipulate Changes made and returned in the Server.
The problem is, it causes a bit of delay between my clicking and the trajectory of the bullet.
Here are the RemoteFunctions and Code that I have currently:
PS: I was having trouble formatting the code on the forums, if anyone has a quick tutorial for that please help me.
Anyways, I’m wondering if there is a better way to communicate the ammo and able to shoot booleans from client to server, or if there is a way to fix delays in general. Thank you!
Delays are inherent when working with remotes because sent and received data needs to cross the network barrier from client to server or vice versa. In the case of RemoteFunctions, it’s a round trip to your server (wherever it’s being hosted) back to your machine.
If you want really effective results, handle the client and server as two different entities. The client should control a gun as if it was authoritative and everything should happen near instantaneously, while the server is more in charge of handling important tasks, verifying and then replicating changes as needed to other clients.
I see, currently I’m handing bullet trajectory and hits on client and having them checked and replicated throughout the rest of the clients. To avoid exploiters, I was convinced I needed to check and verify ammo and shot delay through the server? Should I be handing these on the client instead?
YEP thats what I’ve been doing haha. The delay is when I check if I can shoot or not (depending on if I have ammo or not. Or if I’m reloading or not), and checking my reloading state through a remote function.
Yes, handle ammo on the client. If you need an extra layer of security, track ammo on the server as well. Don’t let the server damage any Humanoids if it’s ammo tracker is at 0, regardless of if your system determined that a valid hit was made or not.