Engine

RemoteFunction

Show Deprecated

The RemoteFunction object facilitates synchronous, two-way communication across the client-server boundary. You can use it to define a custom callback function and invoke it manually by calling RemoteFunction:InvokeClient() or RemoteFunction:InvokeServer(). The code invoking the function yields until it receives a response from the recipient.

In order for both the server and clients to access a RemoteFunction instance, it must be in a place where both sides can see it, such as ReplicatedStorage, although in some cases it's appropriate to store it in Workspace or inside a Tool.

If the result is not needed, it is recommended that you use a RemoteEvent instead, since its call is asynchronous and doesn't need to wait for a response to continue execution. See Remote Events and Callbacks for code samples and further details on RemoteFunction.

Streaming Precautions

Note that if an invoked RemoteFunction creates an instance on the server, there is no guarantee that it exists on the client when the function returns. This is particularly important in places where instance streaming is enabled and when the created instances are BaseParts or Models, since parts that are far away from the player's character may not be streamed to the client, and models that are Atomic depend on whether their parts are streamed. Even if a model is Persistent, there may be some delay between the creation of the model and when it is replicated to the client.

Parameter Limitations

Any type of Roblox object such as an Enum, Instance, or others can be passed as a parameter when a RemoteFunction is invoked, as well as Luau types such as numbers, strings, and booleans, although you should carefully explore the limitations.

Summary

Methods

Callbacks

Properties

Methods

InvokeClient

yields

Invokes the RemoteFunction which in turn calls the OnClientInvoke callback. Since this method is used to communicate from the server to a client, it will only work when used in a Script.

Any type of Roblox object such as an Enum, Instance, or others can be passed as a parameter to InvokeClient(), as well as Luau types such as numbers, strings, and booleans, although you should carefully explore the limitations.

See Remote Events and Callbacks for code samples and further details on RemoteFunction.

Warning

In practice, the server does not often invoke the client, as clients typically do not have information that the server doesn't have, and actions that only a client can take, such as displaying a GUI, typically do not require a callback. As such, RemoteEvent:FireClient() is recommended as an asynchronous method that doesn't need to wait for a response to continue execution.

If you legitimately need to invoke a client from the server, note the following risks:

  • If the client throws an error, the server throws the error too.
  • If the client disconnects while it's being invoked, InvokeClient() throws an error.
  • If the client doesn't return a value, the server yields forever.

Parameters

player: Player

The Player associated with the client to invoke.

arguments: Tuple

Values to pass to the OnClientInvoke callback.


Returns

Values returned from the OnClientInvoke callback.

InvokeServer

yields

Invokes the RemoteFunction which in turn calls the OnServerInvoke callback. Since this method is used to communicate from a client to the server, it will only work when used in a LocalScript.

If a returned result is not needed, it's recommended to use RemoteEvent:FireServer() instead, as its call is asynchronous and doesn't need to wait for a response to continue execution.

Any type of Roblox object such as an Enum, Instance, or others can be passed as a parameter to InvokeServer(), as well as Luau types such as numbers, strings, and booleans, although you should carefully explore the limitations.

See Remote Events and Callbacks for code samples and further details on RemoteFunction.

Parameters

arguments: Tuple

Values to pass to the OnServerInvoke callback.


Returns

Values returned from the OnServerInvoke callback.

Events

OnClientInvoke

Parameters

arguments: Tuple

Returns

OnServerInvoke

Parameters

player: Player
arguments: Tuple

Returns