Reference API Roblox

Engine API

Website

Related

Reference API Roblox

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.

Member index 8

HistoryMember
483InvokeClient(player: Player, arguments: Tuple): Tuple
462InvokeServer(arguments: Tuple): Tuple
462OnClientInvoke(arguments: Tuple): Tuple
524OnServerInvoke(player: Player, arguments: Tuple): Tuple
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Description

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.

History 15

Members 8

InvokeClient

Parameters (2)
playerPlayer
argumentsTuple
Returns (1)
Tuple

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.
This function yields. It will block the calling thread until completion.

History 3

Tags: [Yields]

InvokeServer

Parameters (1)
argumentsTuple
Returns (1)
Tuple

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.

This function yields. It will block the calling thread until completion.

History 2

Tags: [Yields]

OnClientInvoke

Parameters (1)
argumentsTuple
Returns (1)
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.

History 2

OnServerInvoke

Parameters (2)
playerPlayer
argumentsTuple
Returns (1)
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.

History 3

Settings