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

Questions about Remote Events?

Asked by 5 years ago

Hello so we know there is remote events and remote functions but I have questions about them(mainly about remote events) So here are my questions 1.What is the difference of remote events and remote functions? 2.What is different of client and server?(I might look dumb and what i mean is whats the difference when you fire server then when you fire client) 3.When should we use a script or a local script when you use it in a remote event or remote function?

3 answers

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

Hi Mahad,

So, first, RemoteEvents and RemoteFunctions are useful for connecting between the client and the server. I'll explain this real soon and answer your questions procedurally below.


The Difference Between Remote Events and Remote Functions

Remote Events and Remote Functions can both execute code to make things happen, but with RemoteFunction, you can return values. So, it makes it possible to share values from client to server using RemoteFunctions.



The Difference Between Client and Server

The Client is basically our computer or phone or whatever we're using to play the game. The server is like this rectangular computerized box that the client connects to, in order to play with other clients. The server is where many clients connect, and everything(if it's visible of course) that happens on the server can be seen by all the clients connected to that server.

The :FireServer() function of the RemoteEvent activates the ServerScript(Normal Script) that's connected to the RemoteEvent and the :FireClient() function activates the LocalScript that's connected to the RemoteEvent. By connected, I mean they use the .OnServerEvent or the .OnClientEvent on a function in the script.



When To Use Local or Server Script When You Use it With a Remote Event or Remote Function

For RemoteFunction and RemoteEvents, you're going to need both scripts. A server and a local, because RemoteEvents and RemoteFunctions are for communicating between the client and the server. Local Scripts are used in the client, and Server Scripts are used on the Server.


Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
How do you make titles big for every paragraph. User#19524 175 — 5y
0
^ You press # Zafirua 1348 — 5y
0
Put '#' before each line of text you want big. And the more #s you put, the smaller the text gets. 3 is the smallest amount of #s you can have, 4 #s make a weird italicized text. KingLoneCat 2642 — 5y
Ad
Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

Adding onto KingLoneCat's answer on Difference between Remote Event and Functions.

The first difference which he answered pretty well is that Remote Functions expects a response from request whereas Remote Events simply request.

The another difference between Remote Event and Remote Function is that Remote Event can be used for all the players in game.

Major Remote Event functions

  • FireAllClient
    • Fires the event on every single players in the game.
  • FireClient
    • Fires the event on Local Player.
  • FireServer
    • Fires the event on server. Note that the first argument is passed as the Local Player.

On the other hand, Remote Functions are only used for 1 Specific Player

Major Remote Function functions.

  • Callbacks
    • OnServerInvoke
      • Event is invoked when InvokeServer is initiated.
    • OnClientInvoke
      • Event is invoked when InvokeClient is initiated.
  • Yield Functions Called Yield because it waits until it receives the response.
    • InvokeClient
      • Activate the Event and the OnClientInvoke is initialized.
    • InvokeServer
      • Activate the Event and the OnServerInvoke is initialized.

The Final and Another Major difference is Remote Event can be initiated any number of times. What this means is that any number of script can be listened to a single Event. The same rule cannot be applied to Remote Functions. Remote Functions, expects you to return a value. And that value can only be a single value at a particular time. However, do keep in mind that value can be anything.

For Example. Say you have a Remote Event in Replicated Storage and have 2 other scripts listening for it.

-- [Declaration Section]
-- //Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");

-- [Processing Section]
local Fire = function()
    RemoteEvent:FireServer();
end;

-- [Output Section]
Fire();
-- [Declaration Section]
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");

-- [Processing Section]
local OnFire = function ()
    print("I was called!");
end;

-- [Output Section]
RemoteEvent.OnServerEvent:Connect(OnFire);

and

-- [Declaration Section]
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent");

-- [Processing Section]
local OnFire = function ()
    print("I was called X2!");
end;

-- [Output Section]
RemoteEvent.OnServerEvent:Connect(OnFire);

Since they both listen to the same Event, they will both print.

I was called! I was called X2!

Log in to vote
-1
Answered by 5 years ago

The answer to your first question, even I don't understand the difference. Personally, I never use Remote Events and I don't think there is that much indifference.

The answer to 2 is Client is basically the player themselves while server refers to the entire server.

To make this as understandable and possible, GUI(Buttons, Frame etc) should be managed through the Client (Local Script). This is because since these elements are on an individual screen, there is no need for the entire server to handle an update. Plus, no one is gonna see it.

Server refers to literally workspace, what is at play and on. The reason we use FilteringEnabled is so that if an exploiter decides to mess with the server to put the server on fire or something. It will ONLY affect that hacker (only the hacker can see it). The server is basically where you handle physical objects like parts and so on so that it updates for EVERY single player.

You should use a LocalScript when dealing with Screen Elements and you should use a Server Script when dealing with the literal world (workspace).

An example of when you should use RemoteEvents is, for example, you wanted to click a screen button and teleport a part to another part. You would have to Fire a remote event so that then the server knows that has to do something and then handles the teleporting on the server.

Example: Local Script

local b = script.Parent
local RE = game:GetService('ReplicatedStorage').RemoteEvent

b.MouseButton1Down:Connect(function()
    RE:FireServer()
end)

Server

local RE = game:GetService('ReplicatedStorage').RemoteEvent

RE.OnServerEvent:Connect(function(plr) -- the first argument is always player
    -- do something
end)

Hopefully, this gave you a brief understanding. For more information check out Roblox wiki: http://wiki.roblox.com/index.php?title=API:Class/Workspace/FilteringEnabled http://wiki.roblox.com/index.php?title=Experimental_Mode http://wiki.roblox.com/index.php?title=Converting_Experimental_Mode_Games http://wiki.roblox.com/index.php?title=API:Class/RemoteFunction http://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events

Best of luck to you.

0
Also King Lone Cat has a better answer BlackOrange3343 2676 — 5y
0
You use plenty of remotes, though? Also, workspace is not the server, and there are exceptions where client changes replicate. hiimgoodpack 2009 — 5y

Answer this question