Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

4 comments

0

You can use remote events/functions in the same way. I would suggest looking at the Wiki..

0

But with what commands I have to use?

0

Ok, so it's OnClientEvent and FireClient(), i posted the previous comment right before you fix your comment

0

u could use remote functions, those are 2 way communication

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.