Remote Event Call Order

If you call fire the client’s remote events, will the client receive the calls always in the respective order?

For example:

RemoteEvent:FireClient(Player) --call 1
RemoteEvent:FireClient(Player) --call 2
RemoteEvent:FireClient(Player) --call 3

will the client always receive it in order?

2 Likes

I’m fairly sure they do from what I’ve read in other posts as they queue up if many are fired at once. If this turns out false, you could put a “count” variable in the request or something. What is the use case though? Also, don’t fire it too many times as you may hit a limit although no one is sure what that is yet.

1 Like

This all has to do when a client joins an on going game, the client calls must be in sequence bc it’s crucial.

I’m still unclear of when to update a new client thats joining mid game. How are you suppose to know when they’re fully loaded?

The player could fire a “loaded” function or something with a server listener (To know when they are loaded) and then the server could return a table with the values that you would otherwise be sending several times.

I’m fairly certain that they’re received by the client in the order they’re sent, so events are fired in order, too. I’m basing this on my own experience and the fact that Roblox uses TCP, which guarantees that packets are delivered in the order they’re sent. Roblox uses RakNet, which uses both TCP(?) and UDP, so I’m not sure. Apparently RakNet sequences the packets automatically.

https://devforum.roblox.com/t/are-remote-events-guaranteed-to-be-in-order-on-receive/16235

I wish a staff could give an authoritative answer on this.

1 Like

Still though, why fire multiple events over just a single table returned by a RemoteFunction or something. I wouldn’t want to risk the limits they are setting (not sure what they are and I should probably test) as if many players join then firing 3 remote events or however many every time would be a lot of that data limit (I’m assuming).

So when is it safe to fire the client (with remote function or event) after they join?

I’m doing it right after a CharacterAdded event on the server.

I use CharacterAdded and I haven’t had any issues so far.

Remote invocations are queued up and sent over an ordered, reliable stream every few frames.
Order is guaranteed.

43 Likes

Bookmarked. Thank you very much for this reply!

“Invocations” implying only RemoteFunctions or all Remotes?

1 Like

What about

?

Where is this quote from? It’s pretty hard to figure out what I meant without context :slight_smile: edit oops nvm, apparently you can expand this.

I should’ve worded this better. Here’s what I meant:

Event invocations are started on the server in order. However, if they yield execution at any point, the continuation - code that runs after yield - will not be ordered between different invocations. So if you have a user interface that submits a remote event that performs data store updates, you need to be careful about not running more than one at a time - which could be implemented with a remote function since the client will wait for the server to finish updating the data and can block subsequent calls while pending calls are in progress.

5 Likes

So this code may not always print “1 2 1 2”?
But will always either print that or “1 2 2 1”?

Server side:
local id=0
onServerEvent(function()
id=id+1
print(id)
wait(1)
print(id)
end)

Client side:
fireRemote()
fireRemote()

This pseudo-code:

-- Server side:
onServerEvent(function(id)
print("before ", id)
wait(1)
print("after ", id)
end)

-- Client side:
fireRemote(1)
fireRemote(2)

Can print:

before 1
before 2
after 1
after 2

or

before 1
after 1
before 2
after 2

or

before 1
before 2
after 2
after 1

The only guarantees are:

  • “before 1” will happen before “before 2” because events are started in order
  • “after 1” will happen after “before 1” and “after 2” will happen after “before 2” because they run in the same Lua thread in order
2 Likes

That code would print
1
1
2
2
regardless of order;
the above example is more sensible

my guess is it fires in the order that they are queued in order to prevent problems with call order.

1 Like

Ya my example too buggy lol