Best way to make an automatic FPS gun server sided?

Basically, working on an FPS framework for a project. And I’m currently working on the M4A1, but the issue is that the M4A1 is automatic, which has a firerate of 857. Which means 60/857 = 0.11666777 (not accurate), and I have to let other players see the raycast (the bullet go around), so how would I do this without lagging the entire server with remote communications around?

1 Like

You’ll have to calculate however many (roughly 12) raycasts per physics frame all at once. As far as replicating that to clients, I would recommend utilizing random seeds to calculate your recoil. That way, you only have to send the direction and the random seed to the clients, and they should be able to accurately reconstruct the 12-ish raycasts from there.

But the thing is, how would I replicate it to other clients perhaps?

There’s a tutorial on this replication, no other way other than remote events but you can use fire all client to avoid rendering the animations on the server and making the server do less math for the bullet ray and focus on other stuff instead.

But you can use some interpolation to reduce the amount of signals sent like only sending a signal when the gun starts firing and when the gun stops firing then interpolating perhaps but…yeah more safety checks will be needed to be done and finding the position of the character as well for where the bullet is fired from.

Or you can use @MysteriousVagabond idea to reduce the amount of fire all clients events.

Just some ideas to reduce the number of remote events.

BTW, what are your units for the m4a1 fire rate?

857 per nanosecond? :laughing:

Edit:
Nvm, in a PM from @BIackShibe I discovered the exact fire rate in the video
below is actually 3000 rpm :flushed:, that explains why the sound was being loud and buggy.

IDK, if its suitable for multiplayer but maybe you can ask.

yeah but how would i fire all clients without using the server? is there a plausible way?

Sorry, there is no client to client communication in Roblox.

Because of the client-server model, communication between two or more clients must pass through the server. This is typically done as follows:

  1. The sending client calls FireServer() .
  2. On the server, the function connected to OnServerEvent hears this firing and calls FireClient() or FireAllClients() for the intended receiving client(s).

Anyways, if you are concerned about server lag than fire all clients will actually minimize server lag as the server doesn’t have to create the bullets as this task is passed onto the client hence less lag.

Unfortunately the same cannot be said about network latency/lag for the communication :sweat_smile:, however, we can try to limit it using alternative methods like limiting the rate and amount of information sent but then we might have other problems like not knowing where the gun is fired from or damaging the client to server agreement which is crucial in an FPS.

Kinda like the situation where you fire the bullet but it doesn’t do anything because the server think you got killed first by the other guy.

1 Like

One last thing,

Would it be possible to replicate a sound to other clients without disabling/enabling RespectFilteringEnabled?

performance on the demo is fine given you don’t use wait(). it starts throttling and lags the sound otherwise (or so I assume? the sounds were breaking but it takes quite a lot of time to actually throttle)

1 Like

but the issue is that the M4A1 is automatic, which has a firerate of 857. Which means 60/857 = 0.11666777 (not accurate)

857 is far too low an RPM to worry about server lag.

1 Like

Just curious have you tested it with huge numbers?

Is there a certain point where the rpm becomes too high?

If so which one gives in first, the client computer fps, or the networking lag.

at some point wait() just isn’t fast enough and you can’t go any higher, so the RPM is basically infinite
servers can take a lot of punishment. there are a lot of games that send a crapton of useless data around for the sake of it (separating muzzle flash or sounds into their own event on a fm kit i’ve seen floating around is a good example)

2 Likes