Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
7

RemoteFunction and RemoteEvent Tutorial or code?

Asked by
kingdom5 5269 Trusted Snack Break Moderation Voter Community Moderator
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 :)

1 answer

Log in to vote
6
Answered by
2eggnog 961 Moderation Voter
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 5269 — 4y
1
Well, it would need to be in a place that everyone can access. Clients can't access the server storage, so that would be a very bad place to put them. If not the replicated storage, put it in the Workspace or Lighting. 2eggnog 961 — 4y
1
Why isn't this locked yet? It's a very useful question. Griffi0n 305 — 9mo
Ad

Answer this question