Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years 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 53 — 5y
0
But with what commands I have to use? Konethorix 197 — 5y
0
Ok, so it's OnClientEvent and FireClient(), i posted the previous comment right before you fix your comment Konethorix 197 — 5y
0
u could use remote functions, those are 2 way communication supercoolboy8804 114 — 5y

1 answer

Log in to vote
1
Answered by 5 years 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