How Would I Fix a Client to Server Delay (RemoteEvents)

I have a remote event that fires from the client, yet there is a delay. I would wonder how to fix that delay, as it is a gun system and a delay between clicking and shooting is not ideal.

I have no wait() or task.wait() inside of the shooting function.

Server:

script.Parent.Action.OnServerEvent:Connect(function(Play,Action,MousePos,MouseRay,CA)

Client:

script.Parent.Action:FireServer("Shoot",Mouse.Hit.Position)

Remote
image

Game

You will notice a delay when shooting while moving

Hey,

Keep in mind there will always be some amount of delay between the client and server due to latency. As remote events fire from the client to server (or vice versa), there isn’t much you can do about the delay.

Of course, you could always simulate the bullet on the client side to make it show instantly for the shooter, and send the remote event to other players that still need to see the shooting (there will still be a delay between players)

Good luck!

3 Likes

You could “shoot” on the client, then simply send the results to the server. This would atleast appear to be faster (although if you’re really laggy others would be confused on how you hit them, and you might be picked up by anti-cheats)

This be more exploitable tho but like checking on the server should be enough

3 Likes

Well, this still would not fix the delay problem and even if it did, I don’t really want to use this method as I want most things on the server

If you want things on the server, you will have to compromise with the latency. It’s unavoidable, the signal has to travel some distance to communicate

My solution: create visual bullet on client, send hit info to server, validate hit on server, draw bullet on other clients

2 Likes

I dont believe there is any other solution except possibly sending key press info to the server instead

2 Likes

But I don’t understand how I would get rid of the delay, would I have to make a raycast on the client to the mouse position and send its position to the server to create the bullet, therefor getting rid of the delay, while still using remote events?

So basically, creating a raycast on the client, then sending the results to the server.

Yes. You tell the server what you hit rather then telling it to test it out

1 Like

To get rid of the visual delay, you would do a raycast on the client and show the bullet on the client. Then, you would send the event to the server (preferably with some server-side validating to make sure that the information that the client sent is real). The server would then send an event back to all other clients to simulate the bullet, so that other players can still see the bullet and so that the original player doesn’t see the bullet twice (This will be delayed, it is unavoidable). The server would also calculate who the bullet has hit and deal damage etc.

5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.