Most efficient way of making a weapons system?

Hey! I currently am having issues with a weapon system I am creating, there is a ton of server lag. Let me explain how this system works;

There is a module with gun information, for each weapon. The serverscript requires the module, and goes from there. When the player uses the weapon, or shoots with it, it invokes the server, with a table of 5 different information;

  1. MousePosition
  2. The gun Name
  3. The Ammo type
  4. The gun barrel
  5. The gun’s current state ( Reloading, Shooting, ect. )

The server takes this Data, and checks what ammo the gun uses. It then checks the module for that gun, and then does a function to fire the bullet(s). In a module, you can have the gun shoot as many bullets as you want. If its a shotgun, each bullet will get a random area, and then it sub ducts the guns barrel position and mouse position. Once done, it raycasts, and duplicates a beam into a part that is then created. Once this is all done, the bullets will display, if any of the bullets hit a humanoid, it will damage it. The issue is, when in a server, it lags a LOT, and there is a bit of a delay, I lessened the delay by removing a few wait() statements, but now there is still a delay, is this way of guns efficient, or is it not and I should use a different method? How would I reduce the delay?

Video(s)/Image(s);

Any help would be appreciated, thanks!

2 Likes

Because you are doing all of your bullet rendering on the server, your gun is always going to take the time of the player’s ping to fire (which can be significant). To mitigate this, you should be doing the firing and some bullet predictions on the client and the server should be compensating on the ping with the client when firing.

5 Likes

I can confirm this works. I made everything client side, and a bullet visualizer for the other clients. The damage is all server based. Thanks for the help!

1 Like

No problem! Just don’t forget to add a check on the server to make sure the client’s shots make sense and are possible.

1 Like