How do I fix latency with my gun system?

So I am working on an FPS game, and you can shoot and everything. One problem: The shots are late even though they are being processed as fast as possible.
Here’s how the system works:

Every frame, the camera CFrame is being sent to the server and is stored on the server (i’m pretty sure it doesn’t cause lag)
When you click, that’s sent to the server to raycast from the Camera CFrame. Afterwards, if the raycast hit a player than their character is damaged.

People are saying this causes latency issues.

Apparently this is what games use for latency:

How can i do this in my game while still keeping damage on the server? Please help!

There is a serverside timer synchronized for all clients and a method to get a player’s ping. You can remember a certain history of positions (for the other players/npcs they can shoot) and refer to the relevant point in history that a client was experiencing when they fired their weapon. You can make clients send their own current timestamp and ignore timestamps that are too far from the expected value or just infer the timestamp on the server using the ping.

I’m unsure how much Roblox’s physics interpolation interferes with this kind of work.

1 Like

Thanks. Now how can I not do Roblox’s physics interpolation so i get it right? Do I do something similar to the camera system where the HumanoidRootPart CFrame is being sent to the server all the time? Please elaborate a bit more about the latency stuff. I understand it but like not fully understand it.

also, appreciate the ammount of effort you’re putting into this response dele. seen u replying for a while

Roblox already replicates character physics from each client to the server. When firing a shot though, it would be helpful for the client to provide its CFrame for more precision.

The game is always advancing, even while a RemoteEvent is being sent from a client to the server. When it arrives, the server has a new different perspective of player positions, likely where the victim has moved away from the bullet’s trajectory. The server needs to refer to the same point in time that the firing client was in when they took the shot, adjusted even further backwards in time using the client’s ping. That old point in time likely has the same worldview that client did, except for the position of the client itself. It’s also likely that physics and RemoteEvent messages are in tandem enough that you can trust the current perceived serverside view of the client’s position at the time of receiving the RemoteEvent is very close to the one they fired a bullet from.

If you meant some other kind of latency, please let me know and I’ll try my best to focus on that instead.

as you said about physics interpolation, would it be good to keep character positions choppy on the server like most games outside of roblox do and keep the interpolation on the client?

I believe that’s the current design of physics on Roblox. Since the client is interpolating between positions for the victim, they’re at a valid position that the server can record in history and refer to.

Unless you encounter issues with the default interpolation, I don’t believe you need to work around it.