✓ Accepted answer
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)
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 = {...}
end)
function remoteFunction.OnClientInvoke(...)
local 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.
2 comments
Ile give this a try would this also work outside of replicated storeage? with multiple client calling the function/event
Why isn't this locked yet? It's a very useful question.