M MY Multiplayer: Wiki
Side
Kind

triggerClientEvent

Server

Sends an event to the players' clients, which trigger it on source. The function returns before the clients receive it.

bool triggerClientEvent(string eventName, element source, any ... [, player|table|element sendTo = root])

Parameters

NameTypeDescription
sendToplayer|table|elementA player, a table of players, or an element whose descendant players get the event. Left out, it goes to every player. A player listed twice gets it once.default root
eventNamestringThe event's name on the clients.
sourceelementThe element the event happens on, on the clients.
...anyArguments passed to the handlers on the other side: nil, booleans, numbers, strings, elements, vectors and tables of them.

Returns

true if it was sent, false if the event is over 10 MB or a million values.

Elements created before the call reach the clients before the event. For more than 10 MB, use triggerLatentClientEvent.

Example

addEventHandler("onPlayerSpawn", root, function()
    triggerClientEvent(source, "onShowWelcome", source, getPlayerName(source))
end)

triggerClientEvent("onRoundStart", resourceRoot, 300)
NoteThe client only accepts the event if it registered it with addEvent(eventName, true). Otherwise it is dropped, and only the client's log says so.

See also