Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How to make a server-sided script tell a LocalScript to do something?

Asked by
Valualty 137
7 days ago

Like instead of firing the RemoteEvent for a server script to run something, we do the opposite.

0
You can use remote events/functions in the same way. I would suggest looking at the Wiki.. SnazzySpider67 49 — 7d
0
But with what commands I have to use? Valualty 137 — 7d
0
Ok, so it's OnClientEvent and FireClient(), i posted the previous comment right before you fix your comment Valualty 137 — 7d
0
u could use remote functions, those are 2 way communication supercoolboy8804 99 — 7d

1 answer

Log in to vote
1
Answered by 7 days ago

It appears from your question that you think a RemoteEvent can only fire by a local script asking the server to accomplish a task but not the other way around.

Both remotes (RemoteFunction & RemoteEvent) are capable of having a local script tell the server to accomplish a task and having the server tell a local script to accomplish a task. However, the RemoteEvent is capable of having all clients (the computer running the local script) do a task the server asked for.

Due to your question referring to RemoteEvents specifically, I will give you an example of a RemoteEvent causing the server to tell a local script to accomplish a task:

--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)


--Local script

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)

The above example is taken directly from the Roblox Developer Hub. If you would like to learn more about Remotes, such as RemoteFunctions yielding and RemoteEvents not yielding but being able to fire all clients, please check this link.

Ad

Answer this question