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

How to work with RemoteEvents and RemoteFunctions?

Asked by 5 years ago

Yes, I know there are many articles on these but they never make sense to me.

So when I make a game, I usually find using remotes as a last resort for scripting and stuff, because I hardly know how to even use them. How do I specify the information that the remote is supposed to fire?

Example:

Me: wants to fire a event that gives the player money

Event: fires and gives money

How would I specifically 'assign' the information that the remote has to fire? Come someone explain to me how to use RemoteEvents/Functions to me in an easy way? This would be very helpful for making a game for me, because Remotes are pretty useful when making a game obviously.

1 answer

Log in to vote
1
Answered by
Jexpler 63
5 years ago
Edited 5 years ago

A remote event is basically a bridge between the client and the server. For example what if you want a gui to appear once something on the server happens. All the logic for when this happens would need to be in a regular script. But a screen gui can only be modified in a local script. So what do we do? We need a local script to run some code when the regular script tells it to. For example:

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

And in the other script:

--Local Script
RemoteEvent.OnServerEvent:Connect(function(plr)
    plr.PlayerGui.Gui.Enabled = true
end)

A remote event either has one or two parameters. If it's going from server to client it has two. The extra one that it doesn't have from client to server is which player to fire the event to. So in this case we used the plr parameter from our playeradded event so only the player that just joined's gui will be enabled. The parameter that both have is a tuple argument. You can have as many of these as you want. It's information you need on the other side. So let's say you have defined a variable in the regular script that you need in the local script we're going to. You'd do:

RemoteEvent:FireClient(plr,value)

And in the local script we need to add this to the event:

RemoteEvent.OnServerEvent:Connect(function(plrl,value)

Now we have this value from the first script in the second script.

0
This helped me understand Remotes a lot more, thank you very much! sean_thecoolman 189 — 5y
Ad

Answer this question