Still have questions? Join our Discord server and get real time help.
7

# RemoteFunction and RemoteEvent Tutorial or code?

kingdom5 5316
4 years ago

I am using filtering in my game and I need to invoke an action on the server, I haven't found any tutorials and http://wiki.roblox.com/index.php?title=RemoteFunction_and_RemoteEvent_Tutorial#Whether_to_use_RemoteEvent_or_RemoteFunction is no help at all.

if any one has a working example please post it :)

7
2eggnog 966
4 years ago

Personally, when I use them, I place the remote event/function in the Replicated Storage so that everything can access them. To communicate with a client from the server, simply do this:

remoteEvent:FireClient(player,arguments)
--OR
remoteFunction:InvokeClient(player,arguments)


That lets you communicate with a specific client. RemoteEvents have a handy method called FireAllClients, but RemoteFunctions do not have an equivalent.

Now, to handle this client side, here's an example of something you could do in a local script.

remoteEvent.OnClientEvent:connect(function(...)
local args = {...}
--Do stuff with table of args.
end)
--OR
function remoteFunction.OnClientInvoke(...)
local args = {...}
--Do stuff with table of args.
end


Note the difference between how you connect the RemoteEvent and RemoteFunction. The RemoteEvent uses an event, but the RemoteFunction uses a callback.

To communicate from the client to the server, it's very similar. The methods for that are FireServer, InvokeServer, OnServerEvent, and OnServerInvoke. The player is always the first argument in OnServerEvent and OnServerInvoke.

Now of course, you would need to define remoteEvent and remoteFunction yourself, but you seem like you have an idea what you're doing, so I'll leave that up to you.

1
Ile give this a try would this also work outside of replicated storeage? with multiple client calling the function/event kingdom5 5316 — 4y
1
Why isn't this locked yet? It's a very useful question. Griffi0n 305 — 1y