As mentioned in the original documentation, there are several ways to call events within resources.
One particularly interesting approach is the use of latent events.
Although these are rarely utilized in practice, they can be highly beneficial. Let’s go over how to work with them effectively.
What are latent events?
This is a specific function used to transfer large amounts of data between the server and client.
As an example, if we need to send a substantial dataset (such as informations from a database or large server-sided dataset) to the client, we can use TriggerLatentClientEvent.
By leveraging latent events, the player’s network remains unblocked, avoiding potential server kicks due to timeouts when receiving a large data load.
Latent events require a special parameter before specifying event arguments bytes per second, which controls the speed at which data is transmitted.
TriggerLatentClientEvent(eventName, playerId, bytesPerSecond, argument1, argument2, ...)
This method is equally effective for sending data to the server from the client.
TriggerLatentServerEvent(eventName, bytesPerSecond, argument1, argument2, ...)
Note that the final event handler only triggers once all bytes have been
transferred to the target destination and reconstructed into the event
arguments. Therefore, the bytes per second value should be chosen
carefully—not too high, which could overwhelm the network, nor too low,
which could delay the event handler excessively.