Skip to main content

GetRemoteFunction

Provides getting named global RemoteFunction resources.

Functions

GetRemoteFunction

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. Yields
GetRemoteFunction.GetRemoteFunction(namestring) → RemoteFunction

Retrieves a global remote function from the store. On the server, it constructs a new one, and on the client, it waits for it to exist.

tip

Consider using PromiseGetRemoteFunction for a non-yielding version

-- server.lua
local GetRemoteFunction = require("GetRemoteFunction")

local remoteFunction = GetRemoteFunction("testing")
remoteFunction.OnServerInvoke = function(_player, text)
	return "HI " .. tostring(text)
end

-- client.lua
local GetRemoteFunction = require("GetRemoteFunction")

local remoteFunction = GetRemoteFunction("testing")
print(remoteFunction:InvokeServer("Bob")) --> HI Bob
info

If the game is not running, then a mock remote function will be created for use in testing.

Show raw api
{
    "functions": [
        {
            "name": "GetRemoteFunction",
            "desc": "Retrieves a global remote function from the store. On the server, it constructs a new one,\nand on the client, it waits for it to exist.\n\n:::tip\nConsider using [PromiseGetRemoteFunction] for a non-yielding version\n:::\n\n```lua\n-- server.lua\nlocal GetRemoteFunction = require(\"GetRemoteFunction\")\n\nlocal remoteFunction = GetRemoteFunction(\"testing\")\nremoteFunction.OnServerInvoke = function(_player, text)\n\treturn \"HI \" .. tostring(text)\nend\n\n-- client.lua\nlocal GetRemoteFunction = require(\"GetRemoteFunction\")\n\nlocal remoteFunction = GetRemoteFunction(\"testing\")\nprint(remoteFunction:InvokeServer(\"Bob\")) --> HI Bob\n```\n\n:::info\nIf the game is not running, then a mock remote function will be created\nfor use in testing.\n:::",
            "params": [
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "RemoteFunction"
                }
            ],
            "function_type": "static",
            "yields": true,
            "source": {
                "line": 42,
                "path": "src/remoting/src/Shared/GetRemoteFunction.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "GetRemoteFunction",
    "desc": "Provides getting named global [RemoteFunction] resources.",
    "source": {
        "line": 6,
        "path": "src/remoting/src/Shared/GetRemoteFunction.lua"
    }
}