# triggerServerEvent (Client)

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

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Client
- **Category**: Events
- **URL**: https://wiki.mymp.gg/en/triggerServerEvent

## Syntax

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

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `eventName` | `string` | The event's name on the server. |
| `source` | `element` | An element that exists on the server. An element created only on this client is refused. |
| `...` | `any` | Arguments 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

```lua
bindKey("f", "down", function()
    triggerServerEvent("onPlayerBuyItem", localPlayer, 12)
end)
```

### Note

The 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

- [addEvent (Shared)](https://wiki.mymp.gg/en/addEvent.md): Registers a new event under this name. Only then can handlers be added to it and can it be triggered.
- [triggerLatentServerEvent (Client)](https://wiki.mymp.gg/en/triggerLatentServerEvent.md): Sends an event to the server bit by bit, in the background, at no more than bandwidth bytes a second. Meant for large data that must not hold up the rest of the traffic.
- [triggerClientEvent (Server)](https://wiki.mymp.gg/en/triggerClientEvent.md): Sends an event to the players' clients, which trigger it on source. The function returns before the clients receive it.
- [onPlayerTriggerEventThreshold (Server)](https://wiki.mymp.gg/en/onPlayerTriggerEventThreshold.md): Fired when a player calls triggerServerEvent or triggerLatentServerEvent too many times in an interval. The server does nothing else: what to do is up to the scripts.
