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.
Clients invoking the server is often used because the server either has access to information the client does not, or the client is requesting a game action that only the server can perform. When invoked, this calls the method bound to the RemoteFunction by
RemoteFunction/OnServerInvoke. Use from a
If the result is not needed then it is recommended to use a
RemoteEvent/FireServer 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 server when the remote event is invoked by a client. 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 client to the server, you should use
When handling the invocation from the client note that nothing has to be passed in by default (unlike invoking the server where the player is passed in).
The arguments passed to the
Values returned by
RemoteFunctions: Server to Client
Invoking a client is very similar to invoking the server, except in this case the invocation has to pass the player to invoke. The function used to do this is
The client listens for this function to be invoked by binding a function to
RemoteFunction/OnClientInvoke using the assignment operator =, and not with an event within a
LocalScript. When the player (client) is invoked, it will execute the bound function.
-- Server local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local createPopupRequest = Instance.new("RemoteFunction") createPopupRequest.Name = "CreatePopupRequest" createPopupRequest.Parent = ReplicatedStorage Players.CharacterAutoLoads = false local function onPlayerAdded(player) createPopupRequest:InvokeClient(player) player:LoadCharacter() end Players.PlayerAdded:Connect(onPlayerAdded) -- ================================================== -- LocalScript local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local createPopupRequest = ReplicatedStorage:WaitForChild("CreatePopupRequest") local function onCreatePopupRequested() local screen = Instance.new("ScreenGui") screen.Parent = playerGui local closeButton = Instance.new("TextButton") closeButton.Text = "Welcome to the game! Click me to play!" closeButton.Size = UDim2.new(0, 300, 0, 50) closeButton.Parent = screen closeButton.MouseButton1Click:Wait() closeButton.Visible = false end createPopupRequest.OnClientInvoke = onCreatePopupRequested