what can i do with these 2 things please make for me an example its really hard if u dont know where to add it u can add it in replicatedstorage
what can i do with remoteEvent and RemoteFunction?
3 answers
Remote events and remote functions are used to send data from the client to the server or vise versa.
Example of a remote event
--client
remote.OnClientEvent:Connect(function(...)
print("data received!",...)
end)
--server
remote:FireClient(player,"1","2")
The example above would print "data received! 1 2" on the client
A remote function is basically a remote event except you can send data back.
Example of a remote function
--client
remote.OnClientInvoke = function(...)
print("data received!",...)
return "done!"
end
--server
local res = remote:InvokeClient(player,"1","3")
print(res)
The example above would print "data received! 1 3" on the client and "done!" on the server
Also, most people put their remote events and remote function in ReplicatedStorage.
A remoteEvent is used to make things happen between the server and players clients. Which will allow scripts to call code from a LocalScript and vice-versa. The message can be directed from one client to the server, from the server to a particular client, or from the server to all clients. a remoteFunction is very very similar. Clients and Servers. In order to use a RemoteEvent correctly, you need to fire the client and get the onfired in a different script.
Fire:
-- Insert a custom function, make sure it uses :Connect(function() at the end, so you can use :Connect(function(player)
local remEvent = game.ReplicatedStorage:WaitForChild("remote_event_name")
remEvent:fireClient(player)
end)
Recieve Fire:
local remEvent = game.ReplicatedStorage:WaitForChild("remote_event_name")
remEvent.OnClientEvent:Connect(function()
--Any line of code can go here
end)
5 comments
What is the end doing in "fire" script
Causing an error that's what.
I also wouldn't necessarily call it a "custom" function. It is no more than a callback being marked and placed into an encapsulated repository. You have the option to instantiate what's known as an "anonymous" function if you wish; this isn't unique to ':Connect()'
Well, the reason why the end is in the bottom of the script, is because you connect a certain function(() which creates two more lines, the last one being "end)"
I wasn't talking about the receive fire script, I was talking about the first one. This would raise an error: remote:FireClient(plr) end)
They're both used to send information and functions from a client to a server or vice versa.
Basically let's say you have a GUI Button, and the client (local Player) clicks the button. And let's say we wanted everyone in the game to die when that player clicks the GUI Button. What would we do to accomplish this? We'd either use a remote function or a remote event to fire to the server, (which would be a normal script), not a local.
If you want to fire something from a local script to a server script, you would type, RemoteEvent:FireServer(args), then on the server script you'd type RemoteEvent.OnServerEvent.
And then you can fire something from a server script to a local script, but you would instead type in the local script : FireClient(The Player Who You Would Fire To, args)
Here's a wiki on how it works : https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events#:~:text=Remote%20Event.%20A%20RemoteEvent%20is%20designed%20for%20one-way,make%20that%20player%20invisible%20to%20all%20other%20players.
Here's a video tutorial if you don't like reading (By AlvinBlox) :
Remote Events : https://www.youtube.com/watch?v=wCr5VXJ34T4
Remote Functions : https://www.youtube.com/watch?v=XPI3EYelWzY
You should also understand FilteringEnabled, it's a very important aspect of this :)
Here's a wiki on how it works : https://developer.roblox.com/en-us/api-reference/property/Workspace/FilteringEnabled
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
These are poor examples. A). It is advised against making dependent RF invocations to the Client due to response uninsurability. B). Both method calls on the Remote Instances will rise an error due to an unspecified destination point. C). You never declared a variadic parameter, 'data' will only reflect the second argument.
right, I forgot it had to be a variadic param. As for the bad examples they were just supposed to be the baseline of what they do. For the remote function example, it was also just to get him to understand the basics of it. As for the nil remote, it's self explanatory that you should have that replaced to where your remote event/function is.
When I say unspecified destination point, I don't mean pathway to the Instance. You must pass the Client in which you wish to direct the data to...
LOL uhhhhhh lets just say I got back to scripting just 2 days ago
I remember that feeling, I took a break once and boy was it a mess ;)