Delay When Firing Remote Function from Client to Server

I’m having an issue where when I fire a remote function from the client to the server, there’s a pretty decent delay depending on the players ping. The delay is pretty minimal as long as my ping is around 80-90, but anything above causes almost a second of delay. I tested skills in other games, such as Blox Fruits, and even with ping up to almost 200 the skills were activated almost immediately, so what’s wrong with mine?

Is there any way to solve this issue?

1 Like

It might be how you implemented this, but most games will display things on the client even when the server hasn’t processed it already.

I see, that sounds really exploitable though. Could you break it down a bit so I understand how this works?

1 Like

In a simple(r) example, if we wanted to have a punch ability, you would play the punch animation on the client, fire the event, and then on the server perform the checks (including debounce if necessary), and then perform actions that should be secured on the server (could be dealing damage and/or playing an animation.

1 Like

Oh alright. Is this method better/more optimal than doing everything on the server, disregarding VFX? Like what would be the difference between doing everything on the server, such as hitboxes, animations, cooldown checks, etc (not including VFX), and doing what you said?

Those are the same thing. The hitboxes and cooldowns are debounces and “the checks”.

Never played Blox Fruits, so don’t count on my information, but this is my best guess. In Blox Fruits, they most likely fire to the server, and simultaneously let the local player know that the skill has requested activation, and renders it for the local player immediately. When the server fires back to all clients, it would check if the client is not the skill harnesser, as it would have already rendered it for them, so it doesn’t render twice.

Whilst reading this, I thought this may be a bit confusing, so here it is simplified:

-- Fire to server from LocalPlayer
-- Render for LocalPlayer only, instantly
-- Fire to all clients from server
-- Render to all clients except original LocalPlayer, as not to render twice for them

It may seem on your screen that your skill was activated immediately, but for others, it’ll likely be shown to activate at a different point in time.

Little bit of extra information, there are delays firing to server, and firing to client(s).

But to be clear, the delay shouldn’t be reasonably up to a second. If I’m not mistaken, the ping(ms) is
the time it takes for the server to send to the client, so it probably isn’t too different from the delay experienced.

Note that remote functions yield, so if your server code yields, then that gets added to the delay.

Another trick is to do affects on the client predictively.

So if the player uses an ability, maybe show the effect on their client and then send the server the message to show it on other clients. That’s how all FPS games work, otherwise you’d have like 90-400 milliseconds of lag for each shot.

1 Like

I believe one’s ping is only relevant when firing to the server, and receiving from the server. There also may be expensive calculations happening in between which can also increase delay.

Yes, but I was talking about the delay. It is usually better to use network ownership to not use server resources.

NetworkOwnership for rendering effects? That’s unheard of by myself, mind elaborating?

I said it in a confusing way, but you clone the effects on the server and give the client network ownership. The client will anchor the parts (if necessary) and move them around as needed.

That would work, but only if it were a single player game, what about the rest of the clients? Are you going to clone them all on the server?

It would work in any game. Like I said you clone it on the server and the client that fired the event has network ownership.