✓ Accepted answer
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:
game.Players.PlayerAdded:Connect(function(plr)
RemoteEvent:FireClient(plr)
end)
And in the other 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.
1 comment
This helped me understand Remotes a lot more, thank you very much!