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

How do we send a signal from a script to a localscript? [PLEASE READ DESCRIPTION]

Asked by 5 years ago
Edited 5 years ago

I know how to send a signal for a localscript to a script with remote events, but I don't know how do we do the inverse.

Any answers will be accepted if it's working! Thanks


Ok, guys now I know how, but how can we send a name in this signal?

0
I updated my awnser. RBLXNogin 187 — 5y

1 answer

Log in to vote
1
Answered by
RBLXNogin 187
5 years ago
Edited 5 years ago

Remote Events are designed to provide a one way message between the server and clients. This message can be directed from one client to the server, from the server to a particular client, or from the server to all clients.

On the server, you'll take the RemoteEvent and give it the logic

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

RemoteEvent:FireClient()

When working with Remotes you can additionally add conditionals to trigger when the remote is fired. This is good for many functions. Here is a good example of it:

if money > price then
    RemoteEvent:FireClient()
end

Something to notice is that you need a Player Parameter to initiate to which client to run the script to. This can be the most difficult part of the code but there are several methods.

Method 1: PlayerAdded

game.Players.PlayerAdded:Connect(function(plr)
    RemoteEvent:FireClient(plr)
end)

Method 2: GetPlayerFromCharacter() If you have a player's character model (the physical model), you can find the corresponding Player instance for that character (the object in the Players service which has GUIs and the StarterGear and PlayerPack). Read more an the wikia article here: Roblox Developer Hub

Method 3: Fire All Clients If you would like to fire a signal to the Clients from a server script(or so you call script to local script signal) there is a more viable option.

FireAllClients() FireAllClients is used if you would like to run the code for all clients which does not require a player parameter Here is an example:

if plrs >= 7 then
    RemoteEvent:FireAllClients()
end

The FireAllClients() will execute the remote for all of the players(client) in the game currently and is an extremely useful function.

There are several other methods to recieve the player but since you are new I recommend either using FireAllClients() or PlayerAdded() methods/events to get the player. (use Example one that I gave you)

Finally, you controll what happens in the code with your OnClientEvent(). Just like OnServerEvent(), this method allows you to controll how the client (LocalScript) responds to the sent signal.

LocalScript

game:GetService("ReplicatedStorage").RemoteEvent.OnClientEvent:Connect(function()
    --code
end)

Hope this helped (:

0
Here is your solution. Currently I am working on adding more detail, however this is what you do. It uses the same concept from client to server (LocalScript to Script) but swapped RBLXNogin 187 — 5y
0
OHHHHH so instead of doing fireserver, we do fireclient? TheRealPotatoChips 793 — 5y
0
@TheRealPotatoChips YES! That is exactly correct. (By the way I updated the question to include all the details). Just incase, I am also going to explain FireAllClients() for you RBLXNogin 187 — 5y
0
@TheRealPotatoChips read my updated awnser. When using FireClient() there are a bit more rules that you need to understand. Tell me if you have any more questions RBLXNogin 187 — 5y
0
hey there, thanks! TheRealPotatoChips 793 — 5y
Ad

Answer this question