What are remote events and functions and why/when do u use then
Can someone explain to me what are remote events?
2 answers
Both RemoteEvents and RemoteFunctions allow communication between the server and client(s).
RemoteEvents do not return any values when fired but allow for code to be run on the server/client when something happens.
RemoteFunctions return a value that can be used by the invoking party (either the server or a client). They are otherwise similar to RemoteEvents.
As such, RemoteEvents should be used when you do not want a return value, and RemoteFunctions should be used when you do want a return value.
One thing to note: RemoteFunctions are invoked while RemoteEvents are fired.
Here's a brief video on remote events
Re-edited by JesseSong
2 comments
Thanks for the answer
Wait what do u mean return the value.
There's a thing known as the server-client boundary in Roblox. Whatever the server changes in the game affects all players (clients) but the reverse is not true, this was created to help reduce the number of exploiters/hackers in games. Now, sometimes it is necessary to use stuff only available from the client (mouse input, keyboard input are both good examples) and make changes to the server.
For example, you press the shift-button and you want a fireball to shoot out of your arms. Now, if you scripted one using localscripts, no one would be able to see you shooting it; but the server doesn't have a physical keyboard so there's no way it can fire anything. The solution is to use RemoteEvents and RemoteFunctions.
RemoteEvents allow you to either send information to/from the server/client. RemoteFunctions allow you to send information AND get information back (this is called returning) from the server/client.
Here's an example usage of a remote event:
-- server script
workspace.RemoteEvent.OnServerEvent:Connect(function(player, key)
print(player.Name.." pressed "..key)
end)
-- local script
game.UserInputService.InputBegan:Connect(function(input)
workspace.RemoteEvent:FireServer(input.KeyCode)
end)
And of a remote function:
-- server script
workspace.RemoteFunction.OnServerInvoke = function(player, number)
return 52 + number
end)
-- local script
local add52ToThis = workspace.RemoteFunction:InvokeServer(203)
print(add52ToThis)
Of course, these aren't the only ways to use both. There's an unlimited amount, and you will only be able to understand through lots of practice.
3 comments
Wait so basically remote events make it so that everyone can see when like a local script is ‘fired’.
Also thanks for the answer
Technically, no. RemoteEvents allow you to send information to the server and (if you scripted it) have that information change stuff on the server.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
They basically allow scripts and localscripts to communicate with each other