# sendNuiMessage (Client)

> Sends a message to the interface page of the calling resource. The page receives it in the `window`'s `message` event.

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

## Syntax

```lua
bool sendNuiMessage(table|string message)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `message` | `table\|string` | A table, sent as JSON, or a string already in JSON. |

## Returns

`true` if the message was sent. `false` if the resource shows no page or the message is neither a table nor a string (logs a warning).

It only works if the resource declares a page with `<ui src="...">` in its `meta.xml`. A message sent before the page has loaded waits and is delivered once it loads.

## Example

```lua
addCommandHandler("hud", function()
    sendNuiMessage({ action = "show", money = 2500 })
end)
```

### Note

A string reaches the page exactly as written, so it must be valid JSON.

## See also

- [registerNuiCallback (Client)](https://wiki.mymp.gg/en/registerNuiCallback.md): Registers a function the calling resource's interface page calls with a fetch to /name on its own address.
- [setNuiFocus (Client)](https://wiki.mymp.gg/en/setNuiFocus.md): Gives or takes focus from the calling resource's interface page. With focus, the page gets the mouse and the keyboard.
- [sendDuiMessage (Client)](https://wiki.mymp.gg/en/sendDuiMessage.md): Sends a message to a dui's page. The page receives it in the window's message event.
