PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

FireClient

FireClient causes RemoteEvent/OnClientEvent|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 RemoteEvent/FireServer|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 RemoteEvent/FireServer|FireServer.

See also

  • RemoteEvent/FireAllClients|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

Name Type Default Description

The Player that the remote event is being fired to.

The arguments passed to the RemoteEvent/OnClientEvent method.

Returns

Return Type Summary

No return.


Code Samples


RemoteEvents: Server to a Single Client

The server can send messages to the client through remote events in two ways: it can send a message to an individual client or it can send a message to every client at the same time.

In order to send a message to a single client, the FireClient function should be called from the server via a Script.

To listen for the message on the client, a LocalScript needs to connect a function to the OnClientEvent event of the RemoteEvent.

-- Script

local Players = game:GetService("Players")
 
local welcomePlayerEvent = Instance.new("RemoteEvent")
welcomePlayerEvent.Parent = game.ReplicatedStorage
welcomePlayerEvent.Name = "WelcomePlayerEvent"
 
local function onPlayerAdded(player)
	welcomePlayerEvent:FireClient(player)
end
 
Players.PlayerAdded:Connect(onPlayerAdded)


-- ========================================


--LocalScript 

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local player = Players.LocalPlayer
local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent")
local playerGui = player:WaitForChild("PlayerGui")
 
local welcomeScreen = Instance.new("ScreenGui")
welcomeScreen.Parent = playerGui
local welcomeMessage = Instance.new("TextLabel")
welcomeMessage.Size = UDim2.new(0, 200, 0, 50)
welcomeMessage.Parent = welcomeScreen
welcomeMessage.Visible = false
welcomeMessage.Text = "Welcome to the game!"
 
local function onWelcomePlayerFired()
	welcomeMessage.Visible = true
	wait(3)
	welcomeMessage.Visible = false
end
 
welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)