RemoteEvent

✏ Beginners Scripting Guide ✏

https://create.roblox.com/docs/reference/engine/classes/RemoteEvent In this section, we will be discussing remote event. Remote event is an object that can be used to communicate through client to server and server to client. When you are scripting, some cases need communication between the client and server such as sending a game pass prompt when you touched a part.

Now, let's say we got 2 scripts. One is the server script located in ServerScriptService and one is the client script (LocalScript) located in StarterGui. We also insert one remote event in ReplicatedStorage and name it MyRemote.

SERVER USAGE

Client

local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')

local myRemote = ReplicatedStorage:WaitForChild('MyRemote')

-- Communicate the server from the client by using :FireServer() and pass in data to send to the server from the client.
myRemote:FireServer('This is a client message')

Server

local players = game:GetService('Players')
local replicatedStorage = game:GetService('ReplicatedStorage')

local myRemote = ReplicatedStorage:WaitForChild('MyRemote')

myRemote.OnServerEvent:Connect(function(player, data)
   -- Received a message from the client and triggered the block code below.
   -- The first argument of OnServerEvent is always a local player.
   print(data) -- This will print "This is a client message"
end)

CLIENT USAGE

Server

Client

ALL CLIENTS USAGE

Server

Client

Last updated