ReferenceMulti-instance

apex.ipc.handle

Answers calls made with apex.ipc.invoke.

Syntax

apex.ipc.handle(topic: string, handler: (peer: Peer, ...any) -> ...any) -> Connection

Parameters

ParameterTypeDescription
topicstringThe topic that apex.ipc.invoke calls. It cannot start with @.
handlerfunctionCalled with the calling Peer and the call's values; what it returns goes back to the caller.

Returns

TypeDescription
ConnectionDisconnect it to stop answering, or to set a different handler.

Description

A topic has at most one handler in an instance; setting a second raises an error until the first is disconnected. The handler runs as its own task and may wait or yield. An error it raises is passed to the caller, which raises it in turn; so are return values that cannot be sent.

Example

apex.ipc.handle("inventory", function(peer, category)
    local items = {}
    for _, item in game.Players.LocalPlayer.Backpack:GetChildren() do
        table.insert(items, item.Name)
    end
    return items
end)

These are Game executor contracts. Check build requirements and session lifetimes before using them.