Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

RemoteFunction and RemoteEvent Tutorial or code?

1 answer

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

2 comments

1

Ile give this a try would this also work outside of replicated storeage? with multiple client calling the function/event

1

Why isn't this locked yet? It's a very useful question.

This discussion is preserved as it was. New answers, comments, and votes are closed.