# Send Event to a Client from Server

On every Game Instance there is a method called **SendEventToClientFromServer**. This allows you to send a message to any client from the server, you just need to know thier client id.

<pre class="language-javascript"><code class="lang-javascript"><strong>game.SendEventToClientFromServer(RclientId, eventName, messageStruct)
</strong></code></pre>

## Example Implementation in the "client\_sent\_event"

Shoutout to Komatr for improving the docs!

<figure><img src="/files/cwgTuK5pU6P5egNx11if" alt=""><figcaption></figcaption></figure>

<pre class="language-javascript"><code class="lang-javascript"><strong>//Example Implementation, in the "client_sent_event" script
</strong>switch(eventName){
    case "chat":

    var chatMessage = messageStruct.chatMessage //sent by client
    chatMessage = CussWordsFilter(chatMessage)  //some function to clean cuss words
    
    //now send this chat to everyone in the room
    //firstly find the room this sender belongs to, then send the message to everyone
    for(var roomId in game.rooms){
        if(game.rooms[roomId].clients.hasOwnProperty(senderClientId){
            //we found the sender
            //now send the message to everyone here
            for(var clientId in game.rooms[roomId].clients){
                //make a messageStruct to send everyone
                var a = {
                    message: chatMessage,
                    sender: clientId
                }
                game.SendEventToClientFromServer(clientId, "cuss_free_chat", a)
            }
        }
    }
    break;
    
  
}
<strong>
</strong></code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rocket-networking.gitbook.io/docs/server-side-scripting/send-event-to-a-client-from-server.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
