# RemoteEvent

RemoteEvent : `Instance`

## Overview

A RemoteEvent is an Object used to handle events between the client and server, supporting asynchronous, one-way communication.

Since it needs to be accessible from both the server and the client, it should be placed in a shared location such as ReplicatedStorage or Workspace

## Properties

## Methods

### FireAllClients

This method is used by the server to trigger the event connected to a RemoteEvent for all clients.

Since the event is sent to all clients, no Player argument is required.

#### Parameters

| `Tuple` Arguments | <p>These are the arguments passed to the function connected to the OnClientEvent of a RemoteEvent.</p><ul><li>You can pass basic Luau data types such as number, boolean, string, and table.</li><li>Objects like Instances can also be passed.</li><li>However, not all data types are fully supported, so it's recommended to test how they behave before using them.</li></ul> |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
-- Script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")

local function EnterPlayer(player)
    local SomeText = "FireAllClients"
    S2C_DeadEvent:FireAllClients(SomeText) -- Passing arguments
end
Players.PlayerAdded:Connect(EnterPlayer)


-----------------------------------------------------------------------------------
-- LocalScript
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")

local function OnDeadEvent(text)
    print("[OnDeadEvent]", "Parameter : ", text)
end
S2C_DeadEvent.OnClientEvent:Connect(OnDeadEvent)
```

### FireClient

This method is used by the server to trigger the event connected to a specific client's RemoteEvent.

The Player argument must be provided to specify the target client.

If you want to trigger the event for all clients, it's more appropriate to use FireAllClients().

#### Parameters

| `Player` Player   | The Player that will trigger the client's event.                                                                                                                                                                                                                                                                                                                                  |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Tuple` Arguments | <p>These are the arguments passed to the function connected to the OnClientEvent of a RemoteEvent.</p><ul><li>You can pass basic Luau data types such as number, boolean, string, and table.</li><li>Objects like Instances can also be passed.</li><li>However, not all data types are fully supported, so it's recommended to test how they behave before using them.</li></ul> |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
-- Script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")

local SomeText = "FireClient"

local function EnterPlayer(player)
    S2C_DeadEvent:FireClient(player, SomeText) -- Passing arguments
end
Players.PlayerAdded:Connect(EnterPlayer)


-----------------------------------------------------------------------------------
-- LocalScript
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")

local function OnDeadEvent(text)
    print("[OnDeadEvent]", "Parameter : ", text)
end
S2C_DeadEvent.OnClientEvent:Connect(OnDeadEvent)
```

### FireServer

This method is used when a client triggers the event connected to a server-side RemoteEvent.

When the event is triggered, the connected function receives the Player Object of the client that sent the request as its first argument.

#### Parameters

| `Tuple` Arguments | <p>These are the arguments passed to the function connected to the OnServerEvent of a RemoteEvent.</p><ul><li>You can pass basic Luau data types such as number, boolean, string, and table.</li><li>Objects like Instances can also be passed.</li><li>However, not all data types are fully supported, so it's recommended to test how they behave before using them.</li></ul> |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local C2S_EnterPlayer = ReplicatedStorage:WaitForChild("C2S_EnterPlayer")

local SomeNumber = 10
C2S_EnterPlayer:FireServer(SomeNumber) -- Passing arguments


-----------------------------------------------------------------------------------
-- Script
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local C2S_EnterPlayer = ReplicatedStorage:WaitForChild("C2S_EnterPlayer")

local function OnEnterPlayer(player, number)
    print("[OnEnterPlayer]", player.Name, " / Parameter : ", number)
end
C2S_EnterPlayer.OnServerEvent:Connect(OnEnterPlayer)
```

## Events

### OnClientEvent

When FireClient() or FireAllClients() is called on a RemoteEvent instance, all functions connected to its OnClientEvent are run, and the arguments provided during the call are passed along as-is.

#### Parameters

#### Code Samples

```lua
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")

local function OnDeadEvent(text)
    print("[OnDeadEvent]", "Parameter : ", text)
end
S2C_DeadEvent.OnClientEvent:Connect(OnDeadEvent)
```

### OnServerEvent

When FireServer() is called on a RemoteEvent instance, all functions connected to its OnServerEvent are run, and the arguments provided during the call are passed along as-is.

#### Parameters

#### Code Samples

```lua
local ReplicatedStorage = game:GetService("ReplicatedStorage") 
local C2S_EnterPlayer = ReplicatedStorage:WaitForChild("C2S_EnterPlayer")

local function OnEnterPlayer(player, number)
    print("[OnEnterPlayer]", player.Name, " / Parameter : ", number)
end
C2S_EnterPlayer.OnServerEvent:Connect(OnEnterPlayer)
```

## See also

{% content-ref url="../../../manual/script-manual/events-and-communication/remoteevent" %}
[remoteevent](https://docs.overdare.com/manual/script-manual/events-and-communication/remoteevent)
{% endcontent-ref %}
