This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
Calls the method bound to the RemoteFunction by
RemoteFunction/OnClientInvoke for the given
Player. Use from a
If the result is not needed then it is recommended to use a
RemoteEvent/FireClient instead, as its call is asynchronous and doesn’t need to wait for a response to continue execution.
This is used to bind functions to invoke the client when the remote event is invoked by the server. This function is in place to provide a method for communicating between the client and server, which is well documented in this article.
To fire from the server to the client, you should use
In practice, the server does not often invoke the client. Clients typically do not have information the server doesn’t have and the actions that only a client can take (displaying a GUI for instance), often do not require a callback. That said, the server invoking clients is still an action that the Roblox engine will support and may be useful in niche situations.
If a client disconnects or leaves the game while it is being invoked from the server, the InvokeClient function will error. It is therefore recommended to wrap this function in a pcall so it does stop the execution of other code.
The arguments passed to the
Values returned by
RemoteFunctions: Client to Server
When a client wants to use a remote function, it will invoke the server with the
RemoteFunction/InvokeServer function within a
The server listens for this function to be invoked by binding a function to
RemoteFunction/OnServerInvoke using the assignment operator =, and not with an event within a
Script. When the server is invoked, it will execute the bound function.
-- LocalScript local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartRequest = ReplicatedStorage:WaitForChild("CreatePartRequest") local newPart = createPartRequest:InvokeServer() print("The server created this part for me:", newPart) -- ================================================== -- Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPartRequest = Instance.new("RemoteFunction") createPartRequest.Parent = ReplicatedStorage createPartRequest.Name = "CreatePartRequest" local function onCreatePartRequested(player) print(player.Name, "wants to create a new part") local newPart = Instance.new("Part") newPart.Parent = game.Workspace return newPart end createPartRequest.OnServerInvoke = onCreatePartRequested