RemoteEvent

Show Deprecated

A RemoteEvent is designed to provide a one-way message between the server and clients, allowing Scripts to call code in LocalScripts and vice-versa. This message can be directed from one client to the server, from the server to a particular client, or from the server to all clients.

In order for both the server and clients to utilize a remote event, the RemoteEvent object itself must be in a place where both sides can see it. As such, we recommend that you store the RemoteEvent inside of ReplicatedStorage, although in some cases it's appropriate to store it in the workspace or inside a Tool.

If you need the result of the call, you should use a RemoteFunction instead. Otherwise a remote event is recommended since it will minimize network traffic/latency and won't yield the script to wait for a response. For more information, see Remote Events and Functions.

Code Samples

RemoteEvents: Server to a Single Client (LocalScript)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local player = Players.LocalPlayer
5local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
6local playerGui = player:WaitForChild("PlayerGui")
7
8local welcomeScreen = Instance.new("ScreenGui")
9welcomeScreen.Parent = playerGui
10
11local welcomeMessage = Instance.new("TextLabel")
12welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
13welcomeMessage.Parent = welcomeScreen
14welcomeMessage.Visible = false
15welcomeMessage.Text = "Welcome to the game!"
16
17local function onWelcomePlayerFired()
18 welcomeMessage.Visible = true
19 task.wait(3)
20 welcomeMessage.Visible = false
21end
22
23welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)
RemoteEvents: Server to a Single Client (Script)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local welcomePlayerEvent = Instance.new("RemoteEvent")
5welcomePlayerEvent.Parent = ReplicatedStorage
6welcomePlayerEvent.Name = "WelcomePlayerEvent"
7
8local function onPlayerAdded(player)
9 welcomePlayerEvent:FireClient(player)
10end
11
12Players.PlayerAdded:Connect(onPlayerAdded)
RemoteEvents: Client to Server (LocalScript)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
4
5createPartEvent:FireServer(BrickColor.Green(), Vector3.new(10, 20, 0))
RemoteEvents: Client to Server (Script)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = Instance.new("RemoteEvent")
4createPartEvent.Name = "CreatePartEvent"
5createPartEvent.Parent = ReplicatedStorage
6
7local function onCreatePartFired(player, color, position)
8 print(player.Name, "wants to create a part")
9 local newPart = Instance.new("Part")
10 newPart.BrickColor = color
11 newPart.Position = position
12 newPart.Parent = workspace
13end
14
15createPartEvent.OnServerEvent:Connect(onCreatePartFired)
RemoteEvents: Server to Multiple Clients (LocalScript)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local player = Players.LocalPlayer
5local newPlayerEvent = ReplicatedStorage:WaitForChild("NewPlayerEvent")
6local playerGui = player:WaitForChild("PlayerGui")
7
8local welcomeScreen = Instance.new("ScreenGui")
9welcomeScreen.Parent = playerGui
10
11local newPlayerMessage = Instance.new("TextLabel")
12newPlayerMessage.Size = UDim2.new(0, 200, 0, 50)
13newPlayerMessage.Parent = welcomeScreen
14newPlayerMessage.Visible = false
15newPlayerMessage.Text = "A new player has joined the game!"
16
17local function onNewPlayerFired()
18 newPlayerMessage.Visible = true
19 task.wait(3)
20 newPlayerMessage.Visible = false
21end
22
23newPlayerEvent.OnClientEvent:Connect(onNewPlayerFired)
RemoteEvents: Server to Multiple Clients (Script)

1local Players = game:GetService("Players")
2
3local newPlayerEvent = Instance.new("RemoteEvent")
4newPlayerEvent.Parent = game.ReplicatedStorage
5newPlayerEvent.Name = "NewPlayer"
6
7local function onPlayerAdded(_player)
8 newPlayerEvent:FireAllClients()
9end
10
11Players.PlayerAdded:Connect(onPlayerAdded)

Summary

Properties

Events


Fires listening functions in LocalScript when either RemoteEvent:FireClient() or RemoteEvent:FireAllClients() is called from a Script.

OnServerEvent(player: Player, arguments: Tuple): RBXScriptSignal  

Fires listening functions in Script when RemoteEvent:FireServer() is called from a LocalScript.

Methods

FireAllClients(arguments: Tuple): void  

Fires the RemoteEvent.OnClientEvent event for each client.

FireClient(player: Player, arguments: Tuple): void  

Fires RemoteEvent.OnClientEvent for the specified player.

FireServer(arguments: Tuple): void  

Fires the RemoteEvent.OnServerEvent event on the server using the arguments specified with an additional player argument at the beginning.

Properties

Events

OnClientEvent

The OnClientEvent event fires listening functions in LocalScript when either RemoteEvent:FireClient() or RemoteEvent:FireAllClients() is fired by the server from a Script.

This is used to retrieve remote events fired by the server and intended for the client. This event is in place to provide a method for communicating between the server and client, which is well documented in this article. This event retrieves remote events fired by the server to the client.

To fire from the client to the server, you should use RemoteEvent:FireServer() and RemoteEvent.OnServerEvent.

Parameters

arguments: Tuple

The arguments passed to these methods.


Code Samples

RemoteEvents: Server to a Single Client (LocalScript)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local player = Players.LocalPlayer
5local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
6local playerGui = player:WaitForChild("PlayerGui")
7
8local welcomeScreen = Instance.new("ScreenGui")
9welcomeScreen.Parent = playerGui
10
11local welcomeMessage = Instance.new("TextLabel")
12welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
13welcomeMessage.Parent = welcomeScreen
14welcomeMessage.Visible = false
15welcomeMessage.Text = "Welcome to the game!"
16
17local function onWelcomePlayerFired()
18 welcomeMessage.Visible = true
19 task.wait(3)
20 welcomeMessage.Visible = false
21end
22
23welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)
RemoteEvents: Server to a Single Client (Script)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local welcomePlayerEvent = Instance.new("RemoteEvent")
5welcomePlayerEvent.Parent = ReplicatedStorage
6welcomePlayerEvent.Name = "WelcomePlayerEvent"
7
8local function onPlayerAdded(player)
9 welcomePlayerEvent:FireClient(player)
10end
11
12Players.PlayerAdded:Connect(onPlayerAdded)

OnServerEvent

Fires listening functions in Script when RemoteEvent:FireServer() is called from a LocalScript.

This is used to retrieve remote events fired by the client and intended for the server. This event is in place to provide a method for communicating between the client and server, which is well documented in this article. This event retrieves remote events fired by the client to the server.

To fire from the server to the client, you should use RemoteEvent:FireClient() and RemoteEvent.OnClientEvent.

Parameters

player: Player

The Player associated with the client that the FireServer call originates from.

arguments: Tuple

The arguments passed by the FireServer method.


Code Samples

RemoteEvents: Client to Server (LocalScript)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
4
5createPartEvent:FireServer(BrickColor.Green(), Vector3.new(10, 20, 0))
RemoteEvents: Client to Server (Script)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = Instance.new("RemoteEvent")
4createPartEvent.Name = "CreatePartEvent"
5createPartEvent.Parent = ReplicatedStorage
6
7local function onCreatePartFired(player, color, position)
8 print(player.Name, "wants to create a part")
9 local newPart = Instance.new("Part")
10 newPart.BrickColor = color
11 newPart.Position = position
12 newPart.Parent = workspace
13end
14
15createPartEvent.OnServerEvent:Connect(onCreatePartFired)

Methods

FireAllClients

void

The FireAllClients function fires the RemoteEvent.OnClientEvent event for each client.

Unlike RemoteEvent:FireClient(), this event does not take a target player as an argument. Instead it will fire to all clients who have the same remote event connected to an OnClientEvent event.

Since this function is used to communicate from the server to the client, it will only work when used in a Script.

The behavior of this function, as well as other RemoteEvent and RemoteFunction events and functions, is well documented in this article.

There are limitations on the kinds of data that can be passed between the client and server. For more information, see Parameter Limitations.

  • Data can be passed from server to client through remote events in the same way data is passed from client to server. Any extra information can be passed in as arguments to the RemoteEvent:FireClient() and FireAllClients functions. Note that the FireClient function still needs to pass the player to send the message to as the first argument.

Parameters

arguments: Tuple

The arguments that will be passed to all RemoteEvent.OnClientEvent methods.


Returns

void

Code Samples

RemoteEvents: Server to Multiple Clients (LocalScript)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local player = Players.LocalPlayer
5local newPlayerEvent = ReplicatedStorage:WaitForChild("NewPlayerEvent")
6local playerGui = player:WaitForChild("PlayerGui")
7
8local welcomeScreen = Instance.new("ScreenGui")
9welcomeScreen.Parent = playerGui
10
11local newPlayerMessage = Instance.new("TextLabel")
12newPlayerMessage.Size = UDim2.new(0, 200, 0, 50)
13newPlayerMessage.Parent = welcomeScreen
14newPlayerMessage.Visible = false
15newPlayerMessage.Text = "A new player has joined the game!"
16
17local function onNewPlayerFired()
18 newPlayerMessage.Visible = true
19 task.wait(3)
20 newPlayerMessage.Visible = false
21end
22
23newPlayerEvent.OnClientEvent:Connect(onNewPlayerFired)
RemoteEvents: Server to Multiple Clients (Script)

1local Players = game:GetService("Players")
2
3local newPlayerEvent = Instance.new("RemoteEvent")
4newPlayerEvent.Parent = game.ReplicatedStorage
5newPlayerEvent.Name = "NewPlayer"
6
7local function onPlayerAdded(_player)
8 newPlayerEvent:FireAllClients()
9end
10
11Players.PlayerAdded:Connect(onPlayerAdded)

FireClient

void

FireClient causes OnClientEvent to be fired in LocalScripts running for the given Player. Additional data passed to this function is then provided to OnClientEvent; beware of limitations on this data.

Since this function is used for communication from server to client, so it will only work when used by a server-side Script. For client-to-server communication (the other direction), use FireServer. Direct client-to-client communication not possible on Roblox; however, it can be simulated using a Script that relays information received through some other means, such as FireServer.

There are limitations on the kinds of data that can be passed between the client and server. For more information, see Parameter Limitations

See also:

  • FireAllClients, which works similarly but for all Player
  • Remote Functions and Events, which describes related classes, functions and events and also important limitations on the data that can be sent
  • Sometimes a game will need to send information from one client to another. Roblox does not support direct client to client contact, so any communication must first go through the server. This is typically done using remote events (although functions could be used if desired). First, the sending client would call FireServer. On the server, the function connected to OnServerEvent would hear this firing, and itself would then call FireClient.

Parameters

player: Player

The Player that the remote event is being fired to.

arguments: Tuple

The arguments passed to the RemoteEvent.OnClientEvent method.


Returns

void

Code Samples

RemoteEvents: Server to a Single Client (LocalScript)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local player = Players.LocalPlayer
5local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
6local playerGui = player:WaitForChild("PlayerGui")
7
8local welcomeScreen = Instance.new("ScreenGui")
9welcomeScreen.Parent = playerGui
10
11local welcomeMessage = Instance.new("TextLabel")
12welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
13welcomeMessage.Parent = welcomeScreen
14welcomeMessage.Visible = false
15welcomeMessage.Text = "Welcome to the game!"
16
17local function onWelcomePlayerFired()
18 welcomeMessage.Visible = true
19 task.wait(3)
20 welcomeMessage.Visible = false
21end
22
23welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)
RemoteEvents: Server to a Single Client (Script)

1local Players = game:GetService("Players")
2local ReplicatedStorage = game:GetService("ReplicatedStorage")
3
4local welcomePlayerEvent = Instance.new("RemoteEvent")
5welcomePlayerEvent.Parent = ReplicatedStorage
6welcomePlayerEvent.Name = "WelcomePlayerEvent"
7
8local function onPlayerAdded(player)
9 welcomePlayerEvent:FireClient(player)
10end
11
12Players.PlayerAdded:Connect(onPlayerAdded)

FireServer

void

The FireServer event fires the RemoteEvent.OnServerEvent event on the server using the arguments specified with an additional player argument at the beginning.

Since this function is used to communicate from the client to the server, it will only work when used in a LocalScript.

When firing from the client note that nothing has to be passed in by default (unlike firing to the client from the server - where the player is passed in).

The functionality of this function, as well as other RemoteEvent and RemoteFunction events and functions, is well documented in this article.

There are limitations on the kinds of data that can be passed between the client and server. For more information, see Parameter Limitations

Parameters

arguments: Tuple

The arguments passed to the RemoteEvent.OnServerEvent method.


Returns

void

Code Samples

RemoteEvents: Client to Server (LocalScript)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")
4
5createPartEvent:FireServer(BrickColor.Green(), Vector3.new(10, 20, 0))
RemoteEvents: Client to Server (Script)

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2
3local createPartEvent = Instance.new("RemoteEvent")
4createPartEvent.Name = "CreatePartEvent"
5createPartEvent.Parent = ReplicatedStorage
6
7local function onCreatePartFired(player, color, position)
8 print(player.Name, "wants to create a part")
9 local newPart = Instance.new("Part")
10 newPart.BrickColor = color
11 newPart.Position = position
12 newPart.Parent = workspace
13end
14
15createPartEvent.OnServerEvent:Connect(onCreatePartFired)