Class
RemoteFunction
An object which facilitates synchronous, two-way communication across the
client-server boundary. Scripts invoking a RemoteFunction yield until
they receive a response from the recipient.
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.
Methods 2#
| InvokeClient | Invokes the RemoteFunction which in turn calls the
OnClientInvoke callback.Yields |
| InvokeServer | Invokes the RemoteFunction which in turn calls the
OnServerInvoke callback.Yields |
InvokeClient(player: Player, arguments: Tuple): Tuple#
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.
| Name | Type | Default | Description |
|---|---|---|---|
player | Player | The Player associated with the client to invoke. | |
arguments | Tuple | Values to pass to the
OnClientInvoke callback. |
Returns
Tuple— Values returned from theOnClientInvokecallback.
InvokeServer(arguments: Tuple): Tuple#
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.
| Name | Type | Default | Description |
|---|---|---|---|
arguments | Tuple | Values to pass to the
OnServerInvoke callback. |
Returns
Tuple— Values returned from theOnServerInvokecallback.
Callbacks 2#
| OnClientInvoke | Callback for when the RemoteFunction is invoked with
InvokeClient(). |
| OnServerInvoke | Callback for when the RemoteFunction is invoked with
InvokeServer(). |
OnClientInvoke(arguments: Tuple): Tuple#
This callback is called when the RemoteFunction is invoked with
InvokeClient(). When the bound
function returns, the returned values are sent back to the calling server.
See Remote Events and Callbacks for
code samples and further details on
OnClientInvoke.
| Name | Type | Default | Description |
|---|---|---|---|
arguments | Tuple | The parameters sent through
InvokeClient(). |
Returns
Tuple— Values returned by the callback function.
OnServerInvoke(player: Player, arguments: Tuple): Tuple#
This callback is called when the RemoteFunction is invoked with
InvokeServer(). When the bound
function returns, the returned values are sent back to the calling client.
See Remote Events and Callbacks for
code samples and further details on
OnServerInvoke.
| Name | Type | Default | Description |
|---|---|---|---|
player | Player | The Player associated with the client that the
InvokeServer() call originates
from. | |
arguments | Tuple | The parameters sent through
InvokeServer(). |
Returns
Tuple— Values returned by the callback function.
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild