Weapon server lag

The lag starts when a few players start spamming their guns. I am not sure how many rounds per seconds, but it isn’t that high. I feel like the server-lag happens is due to everything being handled by the server. It is too much for the server to fire rays, create tracers which use tweens to animate and create particles.

Note: I am using a object pooling for both tracers and particles.

Then do it on the client I simulate projectiles with models on the client, and on the server make a projectile which raycasts without a model.

1 Like

I am working on a new system, which fires gun on both local and server sides. The server only checks if the shot was valid and tells other clients to draw tracers.

After you work on that system, the lag will be reduced tremendously, by doing client side projectiles, and non model server projectiles, I can handle 800 projectiles a second.

What about too many raycasts? I have a custom mouse raycast to ignore some parts, then I have to raycast on client in the direction of where mouse hit, then the server has to raycast also in the direction of mouse hit, to make sure the shot was valid. I feel like the amount of raycasts might affect performance.

I raycast to the next point of my destination for each bullet, and they travel 400 studs, with a velocity of 400. This happens every frame so I create raycasts for EACH bullet 60 times. And I can handle 400 bullets a second so that;s a lot of raycasts, raycasting is a cheap process. Plus this is done on the server and the client.

Basically raycasting is super cheap and shoudn’t affect perofmrance. Anything else you do which you think affects performance those might be why?

Heres what I mean if you want to check it out:

I tried your place and I am impressed! Now I really believe that raycasts are very cheap :smiley:

1 Like

Anything else you think affects performance, those might be the thing lagging your game. Serverside bullets with models is a big one.

How about fire-rate? Do you check how long has passed since firing on the client or server? Client-side firerate is not constant for me.

Constant firerate? All I do is put a RednerStepped:wait() and it works, on the client, or do you mean for validlty checks on the server to see if theres to many bullets being shot by the client each second? For that just do a tick() check.

For higher amounts like 1 second just use a renderstepped loop and check if one second has passed between the last shot on the client.

1 Like

When the server starts lagging, sometimes the guns fire faster than they should. I even have a debounce but it still happens.

Your using wait() right? Don’t use wait(1), instead run the loop each hearbeat and checked if an x amount of seconds hass passed before the last shot, using tick()

Combine CanFire() and Fire() into a single remote. The client should just fire Fire() and assume they did. The server can then allow or disallow that action and the client will just see their bullet not do any damage.

Also, clients should draw their own bullets as soon as they fire.

1 Like

Just a useful resource: Avoiding wait() and why

Im not talking about wait() Renderstepped:Wait(), im telling him not to use wait()

1 Like

If I combine CanFire and Fire, how will the client know if shot happened? Due to security reasons, the canFire() function checks if there is enough ammo and firerate. So then how will the client know if there is enough ammo or if client can fire?

They do the check locally, and then the server confirms later. You don’t want a full round trip network delay between the client pressing fire and the gun firing!

Why are you doing client ammo checks on the server, just make an ammo system on the client and the server. Subtract 1 from the server and the client when they shoot. If the ammo is 0 then don’t register the server projectile for hit detection.

if im saying it confusilgly ask me so I can explain it better.

1 Like

Yeah I understand what you mean, I just haven’t tried it out yet. I was still waiting for other solutions, but looks like your one is the best.

Oh sorry, I thought you didn’t understand what I was saying, if you want any other tips PM me, I have a lot of tips and tricks for gun systems.

1 Like