Remote function delay

There seems to be a short delay, like 0.1 seconds, in the InvokeServer() method when calling a serverside function from the client.

It might not be much, but in my game when the bullet system uses this sort of method, the 0.1 second delay really throws players off when firing the gun, as you would expect to see the gun be shooting out the bullet the moment you click your mouse.

Will there be any updates in the near future to reduce the time delay between calling functions from serverside and clientside?

3 Likes

This was one of my main worries when I started using them, however it seems to be pretty much instant for me. Maybe it is the amount of times you use the remote function that causes the delay, with all of those bullets and things everywhere in your game (I presume itā€™s your game you are talking about).

Is there anything that you can remove to cut down the amount of times you use the remote function?

Network latency could be another reason for the delay. (If you arenā€™t testing with a self hosted server)

And, like Decompiler said, the more requests you send may cause more of a delay.

Even if I am in an empty server and shoot one bullet, the delay is still there.

Very odd.

You sure there isnā€™t a wait() anywhere in the code before the bullets are fired? Is there any code that could possibly take some time to complete? Because there is absolutely no delay for me when I use it. Or at least not noticeable.

Hmm could you give me a link to the place where you have it used?

I can see that if I revert back to simply using localscripts, thereā€™s no delay with the shooting.

But then, forgot to add:

I canā€™t just use localscripts because dealing damage to humanoid of character must be done in server-side, otherwise the humanoid health gets messed up when updated locally.

The current way that Iā€™m doing it so far without remote function is:

Localscript controls bullet movement, hitscans
If a player is hit, the localscript saves some values into intvalues and objectvalues
Localscript then clones a script, places the values into the script, and parent the script to a part that is then parented to the workspace
New server side script carries out damage dealing and data persistence for points

As you can see, itā€™s super hacky and inefficient, but surprisingly has no noticeable delay when the game is running fine.

Try Here.

This place uses RemoteFunctions and works well. The other bits are broken but donā€™t mind them.

I used RemoteFunctions in my game to be able to access the chat system through local scripts and didnā€™t notice any delay, then again it wouldnā€™t be very noticeable given the context I used it in.

Hmm seems like the problem is that I have too many arguments =P

Hereā€™s the order of the type of arguments I pass

workspace.FireBullet:InvokeServer(int, string, vector3, vector3 + random vector3, int, int, int, int, int,bool)

6 int values
1 string
2 vectors
1 bool

The client still needs to tell the server that you clicked, and thereā€™s a base delay for this based on your location and distance to the Roblox servers. For some people this is a very short delay (> 50 milliseconds) while for others the delay is rather long. For me, this delay is about 200 to 300 milliseconds, even if the place is an empty baseplate with no other players connected.
This is known as the ā€˜Pingā€™ of a player.

Thereā€™s no way to remedy this delay. You can, however, make it seem like you fired instantly by creating the effect clientside as soon as you clicked.

The delay is pretty noticeable when you compare it with StringValue/Other value objects when transfering data from server to client or vice-versaā€¦

RemoteFunctions should be the same in terms of latency as the data ping (round-trip latency for getting a packet from the client to server and back).

We have a stats panel that shows two values: click Ctrl+Shift+F3 to bring up the base network stats, and then hit Shift+1 several times until the panel on the right shows ā€œRaknetā€.

What is the ping value in the left panel (below ā€œMTU Sizeā€/ā€œPingā€) and what is the value in the right panel?

I had to stop sending and recieving RemoteFunctions from the PlayerGui because the delays were ridiculous.
It would usually throw the ping up to at least 1000 for a brief second, causing undesired effects.

The memory it uses is a bit expensive when you are using lots of them at a pretty rapid rate.

I was originally storing all forms of information inside of a single Engine script, and a ā€œrepresentation of a ServerOperatorā€ that contained the invokes that the client could grab information from was located in the Workspace

I donā€™t know what I did exactly, but it was making the server run extremely slow. Its fixed now, but I have to use a few values to get information about the games state.

On a side note, this is the hierarchy of Murder. Every object in the game is stored within the MurderGame object in the workspace (except for the camera and terrain of course)

MurderGame
     GameContent
          Map
               Loot
               Content
               Spawns
               SpectateCams
          Players
          Bodies
          Footprints
          Voices
               Male
                    help
                    funny
                    morose
                    scream
               Female
                    help
                    funny
                    morose
                    scream
          Other
     ServerOperator
          ClientKilledPlayer
          GameMessage
          DropWeapon
          GLOBAL_STATE
                 State
                 Message
                 Time

litozinnamon, do you have any code snippets that show how you used remote functions before?

Well it can get complex considering what Iā€™m using it to do, so Iā€™ll simplify and show the variables I used.


Server side script:

function fireBullet.OnServerInvoke(player, ID, weapon, start, target, maxD,minD, speed, drop, strength, flash)
coroutine.resume(coroutine.create(function()
projectile(player,ID,weapon, start, target, maxD,minD, speed, drop, strength,flash)
end))
end

----- ā€œprojectile(ā€¦)ā€ spawns the bullet, contains a loop that keeps track of the bullet position, and manages hitscansā€¦ ect.


Client side script:

local ID = 1000
local gunType = ā€œAutomaticā€
local maxD = 40 ā€”max damage
local minD = 20 ā€” min damage
local bulletSpeed = 800
local bulletDrop = 0
local strength = 3 ā€” wall penetration strength
local flash = true ā€” muzzle flash on
local startPos = (Tool.Handle.CFrame).p
local endPos = Humanoid.TargetPoint
local spread = 50 ā€” hipfire spread value
local random = Vector3.new((math.random(-spread, spread) , (math.random(-spread, spread) , (math.random(-spread, spread)

workspace.FireBullet:InvokeServer(ID,gunType, startPos, endPos + random, maxD,minD, bulletSpeed, bulletDrop, strength,flash)

I imagine that the sheer number of arguments Iā€™m passing is the reason for the delay.

Again, I used remote function somewhere else in a completely different way, but I still get some sort of delay. Actually in this case, it seems to be even longer, like 0.5 seconds to sometimes 1 full second before it fully executes properly.

This time it is a localscript that invokes a function on the server to clone a model stored on the server side storage. The server side function returns the model to the localscript, which is then parented to the camera of the client.

Code snippet used:

Server side script:

local store = game.ServerStorage

function LoadGun.OnServerInvoke(player,gun)
local model = store:findFirstChild(gun):Clone()
model.Parent = game.Lighting
return model
end

-----Note: For some reason the model has to be parented to something, otherwise the model returned becomes nil. Not a big problem as it is solved by parenting to lighting before returned to the client.

Client Side Script:

local gunModel = LoadGun:InvokeServer(weapon.Name)
gunModel.Parent = workspace.CurrentCamera


Perhaps this time, while I have significantly less arguments, the model that Iā€™m returning is quite heavy. They are detailed gun models that have around 100 parts on average.

The link of this example is here, when you change your primary or secondary weapon.

[quote] RemoteFunctions should be the same in terms of latency as the data ping (round-trip latency for getting a packet from the client to server and back).

We have a stats panel that shows two values: click Ctrl+Shift+F3 to bring up the base network stats, and then hit Shift+1 several times until the panel on the right shows ā€œRaknetā€.

What is the ping value in the left panel (below ā€œMTU Sizeā€/ā€œPingā€) and what is the value in the right panel? [/quote]

left side


General (MTU Size, Ping)
1492, 700-1000ms

right side


ping: 651 avg: 663 best: 293

I checked by loading a model with only 3 parts, the delay is still there with 0.5 - 2 seconds. Part count is irrelevant and negligible.