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?
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.
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?
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.
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.
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.