API: ClientEvent
Returned by NetRay:GetEvent or NetRay:RegisterEvent on the client. Handles client-side logic for unidirectional events.
Methods
:OnEvent(callback: function)
Registers a handler function to be called when this specific event is received from the server. The processing order depends on the priority set during the event's server-side registration.
callback(data: any):data: The payload sent by the server (automatically type-checked iftypeDefinitionwas provided during registration).
Example:
local serverMessageEvent = NetRay:GetEvent("ServerMessage")
serverMessageEvent:OnEvent(function(data)
print("Message from server:", data.text)
-- Update UI.ShowNotification(data.text)
end)
:FireServer(data: any)
Sends the event and associated data payload to the server.
data: The data payload to send (will be type-checked against the server'stypeDefinitionupon arrival if defined).
Example:
local playerInputEvent = NetRay:GetEvent("PlayerInput")
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.Space then
playerInputEvent:FireServer({ action = "Jump", pressTime = input.TimePosition })
end
end)
Properties (Internal)
While not typically accessed directly, a ClientEvent instance holds references to:
Name: The event name string.Options: The options table passed during registration (or defaults).ClientManager: The parentClientManagerinstance.RemoteEvent: The underlying RobloxRemoteEventinstance.