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?
Hi Mahad,
: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.Thanks,
Best regards,
~~ KingLoneCat
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
FireClient
Local Player
. FireServer
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.
OnServerInvoke
Event
is invoked when InvokeServer
is initiated. OnClientInvoke
Event
is invoked when InvokeClient
is initiated. InvokeClient
Event
and the OnClientInvoke
is initialized. InvokeServer
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!
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.