Class · inherits Instance
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.
About RemoteFunction
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
(player: Player, arguments: Tuple) → TupleYieldsInvokes theRemoteFunctionwhich in turn calls theOnClientInvokecallback.Invokes the
RemoteFunctionwhich in turn calls theOnClientInvokecallback. Since this method is used to communicate from the server to a client, it will only work when used in aScript.Any type of Roblox object such as an
Enum,Instance, or others can be passed as a parameter toInvokeClient(), 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.FireClientis 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.
InvokeServer
(arguments: Tuple) → TupleYieldsInvokes theRemoteFunctionwhich in turn calls theOnServerInvokecallback.Invokes the
RemoteFunctionwhich in turn calls theOnServerInvokecallback. Since this method is used to communicate from a client to the server, it will only work when used in aLocalScript.If a returned result is not needed, it's recommended to use
RemoteEvent.FireServerinstead, 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 toInvokeServer(), 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.
Callbacks 2
OnClientInvoke
(arguments: Tuple) → TupleCallback for when theRemoteFunctionis invoked withInvokeClient().OnServerInvoke
(player: Player, arguments: Tuple) → TupleCallback for when theRemoteFunctionis invoked withInvokeServer().
RemoteFunction also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.