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 :)
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.