M MY Multiplayer: Wiki
Side
Kind

triggerServerEvent

Client

Sends an event to the server, which triggers it on source there. The function returns before the server receives it.

bool triggerServerEvent(string eventName, element source, any ...)

Parameters

NameTypeDescription
eventNamestringThe event's name on the server.
sourceelementAn element that exists on the server. An element created only on this client is refused.
...anyArguments passed to the handlers on the other side: nil, booleans, numbers, strings, elements, vectors and tables of them. Elements created only on this client are refused.

Returns

true if the event was queued to send, false if there is no connection to a server, it is over 10 MB or too many events are already waiting to go out.

On the server, the handlers' client global is the player who sent the event, and sourceResource is nil. For more than 10 MB, use triggerLatentServerEvent. The client sends at most 192 KB and 300 event messages a second; the rest waits its turn.

Example

bindKey("f", "down", function()
    triggerServerEvent("onPlayerBuyItem", localPlayer, 12)
end)
NoteThe server only accepts the event if it registered it with addEvent(eventName, true). Otherwise it is dropped, and only the server's log says so.

See also