How would I creating a client to server gun system?

Hello, I’m currently trying to figure out how would I go about creating a gun system that responds instantly, I know it’s easier to do a system that’s server sided, but with server sided systems, the issue is it is delayed due to server ping, which makes the experience less fun.

I’m aware that you can use something like the FastCast module, and it is designed for client to server replication, but I can’t seem to find a good answer on how to achieve that, mostly I only find tutorials that mostly use server sided stuff.

How can I go about making a system using client to server replication?

1 Like
  1. Detect input on the client with UserInputService or ContextActionService
  2. If a gun is equipped, use fastcast to make client side visuals of the bullet(that serve no other purpose than effects), while sending the hit position of your mouse at the same time through a remote event.
  3. Server recieves the hit position and does sanity checks like doing it’s own raycast, checking if the player can fire the gun, maybe a little lag compensation, etc.
  4. If shot is valid then damage the target’s health accordingly

So basically cast the ray from the client, create the effect, detect if it hits a player and if it does, damage the player on the server.

That could work, the problem is, how could I have the effects also be on the server for other players to see?

When the server register’s a hit for ClientA(example name), then the server can use a remote event to send visual data Ex. (StartPosition, EndPosition, A Name lookup in a modulescript for more specific visual information to reduce network usage) to each client except ClientA or the player who fired the gun, then when every other client recieves the start, end and a lookup key, they recreate the shot for their own client.

Gotcha, thanks man I’ll see what I can do!