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

Can someone explain to me what are remote events?

Asked by 2 years ago

What are remote events and functions and why/when do u use then

0
They basically allow scripts and localscripts to communicate with each other JustinWe12 723 — 2y

2 answers

Log in to vote
4
Answered by 2 years ago
Edited by JesseSong 2 years ago

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

0
Thanks for the answer TypicalVictorlks 17 — 2y
0
Wait what do u mean return the value. TypicalVictorlks 17 — 2y
Ad
Log in to vote
2
Answered by 2 years ago

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.

0
Wait so basically remote events make it so that everyone can see when like a local script is ‘fired’. TypicalVictorlks 17 — 2y
0
Also thanks for the answer TypicalVictorlks 17 — 2y
0
Technically, no. RemoteEvents allow you to send information to the server and (if you scripted it) have that information change stuff on the server. radiant_Light203 1166 — 2y

Answer this question