Remoteevent and Remotefunctions are the same?

So when I understood it right Remoteevent and Remotefunctions are litterly the same.

Remoteevent just give things etc.
and Remotefunction is the same as but it does check if the player really got it - just good for exploiter?

I mean Remotefunctions are just good for exploiters because I can check with Remotevent that too, or am I wrong - Its just not so safe as with Remotefunctions. Because with the OnClientEvent, OnServerEvent I can do it with Remoteevent.

Or is there more than that?

This post was flagged by the community and is temporarily hidden.

This is RemoteEvent
Why?
—OnServerEvent
FireClient(Debounce)

–OnClientEvent
prameter(debounce)

if debounce == true then
print(“Hello”)
end???

They are not exactly the same, sure they both are used for connection between client and server but the way they do it is different.

Remote Events are used for one sided communication, which means when client sends data to server (or vice versa), it doesn’t expect a response and just moves on with executing the code.

Remote functions on the other end are used for 2 sided communication, which means when client invokes server it yields the coroutine it’s in until server returns a response and vice versa.

They both have different use cases but you get the idea.

2 Likes

extremly well explained!!

But just one question. Why should I use Remotefunctions? because it could even crash my game???

It says don’t use RemoteFunction:InvokeClient() function because you know, you should rarely ever trust the client since they can yield your code if you didn’t build it properly.

But you can still use RemoteFunction:InvokeServer() without worrying about client breaking your serverscript.

1 Like

But is it possible to make a Remotefunction connection between Client and Client, because we know bindableevent woudnt be possible here. Because its not the same as Remotefunction and we want Remotefunction. So how should that be possible?

Thats a new topic.

I am sure we wont need but is it possible?

ahhh Bindable Function I saw right now does exist

BindableFunction exist for communication between 2 different localscript/scripts.

Unless what you’re talking about is from a client to another client, then you will have to use RemoteEvent:InvokeClient() that is called from a function attached to OnServerInvoke callback.

2 Likes

yes now I understood everything. Thanks man!!!

Remote Events
Remote events send data to the specified place without checking if the other place received it. This means that it can send anything between the server-to-client and client-to-server. You can imagine this like sending someone a notification of an event, you send it to inform them, however you don’t expect a response.

--Script
local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent
remoteEvent:FireAllClients('Hello')
print('Hello World')

This when on the server would send the string “Hello” on every every client, and the script would continue right on and print “Hello World” even if it’s the only script in the game. The server should always use remote events. Remote Events also use a :connect() to specify a response.

--Local Script
local remoteEvent = game:GetService('ReplicatedStorage').RemoteEvent
remoteEvent.OnClientEvent:Connect(function(data)
    print(data) --Prints Hello
end)

Keep in mind you can also send data to the server from the client from using :FireServer() rather than :FireClient(), however you can not FireClient from the Client or FireServer from the Server.

Remote Functions
A remote function treats communication a little differently. Remote functions wait for a response, meaning that it should only be used for client-to-server communication. Think of it as an RSVP, you send it out and wait for their response. (However imagine in this case you don’t host the event unless they respond.)

--Script
local remoteFunction = game:GetService('ReplicatedStorage').RemoteFunction
response = remoteFunction:InvokeClient(game.Players.Player1, 'Hello')
print('Hello World')

This is where it gets a little bit different than a remote event. If you were just to throw this into a script in ServerScriptService and ran it without a client response, it wouldn’t print “Hello World”! Why? Well because RemoteFunctions hang (or more known as wait), for a response from the client. Responses for remote functions are also a little bit different, with it being a function you set to the OnClientInvoke property of RemoteFunctions. To send data from the invokee to the invoker you must simply return something from the function.

--Local Script on Player1
local remoteFunction = game:GetService('ReplicatedStorage').RemoteFunction
local function respond(data)
    return data + ' to you too!' --Would send the server "Hello to you too!"
end

With this added, the server will now print “Hello World” as it got a response. The response variable from the script would also now contain the string “Hello to you too!”. The example here should not be used in production. The server should in practice never invoke the client as if an exploiter disables the script for the invoke or an error happens that breaks the local script, the script on the server will hang forever which is bound to cause more logic breaks.

Client-to-Client Communication
You also seem interested in client-to-client communication. If you mean client communication as in the same client sending data to another script, then you can simply use bindable functions/events which is a little different than remotes. However if you are talking communication from one client to a different client, you would have to have the server act as a middle man.

--Local script
remoteEvent = game:GetService('ReplicatedStorage'):FindFirstChild("RemoteEvent")

function clientToClient(clientName, data)
    remoteEvent:FireServer(clientName, data)
end

function clientResponse(clientName, data)
    return clientName + ' sent ' + data
end

clientToClient(Player2, 'Hi') --Imagine this was only called from Player1's client.
print(remoteEvent.OnClientEvent:Connect(clientResponse)) --On Player2 this would print 'Player1 sent Hi' 

This would be the client side, and the server side would look like this.

--Server
remoteEvent = game:GetService('ReplicatedStorage'):FindFirstChild("RemoteEvent")
remoteEvent.OnServerEvent:Connect(function(player, sendPlayer, data) --Ideally you'd want some input validation here.
    remoteEvent:FireClient(sendPlayer, player, data)
end)

This would allow the clients to interact each other with the server acting as the middle man to move messages. Obviously you want some validation the clients should be able to message each other, the data sent is correct, etcetera. Hopefully this helped you understand!