RemoteEvent is a class that provides a one-way communication method between a server and a client and a client-client.
Description
RemoteEvent is an object that enables asynchronous one-way communication between clients and servers, which allows clients and servers to exchange data with each other and is used to implement various interactions in the game.
Key Features
Asynchronous communication: RemoteEvent runs the following code immediately without waiting for a response when sending and receiving data. This is advantageous for minimizing network delays and keeping the flow of the game smooth.
One-way communication: You can transfer data from clients to servers, from servers to specific clients, or from servers to all clients.
Location: Remote Event objects are typically stored in Replicated Storage, allowing access to both the client and the server.
Properties
Methods
FireServer
The FireServer method executes server-side functionality within the context of Lua or initiates communication with a server for data transfer.
The OnClientEvent is an event that is fired when the server communicates with the client via RemoteEvent. It is commonly used to notify clients about specific server actions or send data from the server to the client. This event is useful for handling client-side logic based on server-triggered interactions or updates.
Parameters
Code Samples
local ReplicatedStorage = game:GetService("ReplicatedStorage") local S2C_DeadEvent = ReplicatedStorage:WaitForChild("S2C_DeadEvent")localfunctionOnDeadEvent(text)print("[OnDeadEvent]", "Parameter : ", text)endS2C_DeadEvent.OnClientEvent:Connect(OnDeadEvent)
OnServerEvent
OnServerEvent is an event that is triggered when the client communicates with the server using RemoteEvent.
It is used for handling and processing data or actions sent by the client to the server.
This event is particularly useful for managing server-side logic based on client-triggered interactions or requests.
Parameters
Code Samples
local ReplicatedStorage = game:GetService("ReplicatedStorage") local C2S_EnterPlayer = ReplicatedStorage:WaitForChild("C2S_EnterPlayer")localfunctionOnEnterPlayer(player,number)print("[OnEnterPlayer]", player.Name, " / Parameter : ", number)endC2S_EnterPlayer.OnServerEvent:Connect(OnEnterPlayer)