How to: user remote facilities correctly
tutorial designed and presented by Kostiskat
Recommended material for this tutorial:
- Client-Server Model | Roblox Creator Documentation
- Bindable Events and Functions | Roblox Creator Documentation
: Introduction
Hello, everyone! As I am embarking on a new series of posts, here on the DevForum, I would like to officially introduce myself with this first topic regarding remote facilities (events & functions). This is my first post, so if you have any constructive feedback, feel free to post below. I try to use real-life and comprehensive examples so everyone can understand. Enjoy my first tutorial!
: What are remote facilities?
I am pretty sure every developer in Roblox has come across Remote Events and/or Remote Functions during their career. Learning how to use them is fairly simple and once you get the hang of them, they unlock a whole ton of accessibility possibilities and can allow you to add more features to your game.
Essentially, remote events and remote functions allow the developer to establish communication with the server and the client model. But I don’t want to bore you with programming details, so let’s move to a simple example; imagine you are using your smartphone to call a colleague at work to convey some information or facts regarding a topic. Of course, telepathy doesn’t exist! So someone will have to tell the co-worker certain stuff and certain orders. So you grab the phone and start communicating with them and transfer certain tasks and information for them to execute. Now instead of the You-Colleague model, imagine the server-client model. The client cannot know what the server is up to telepathically, so remote facilities work as a telephone, the client/server picks up, and obtains useful information and performs certain tasks.
: What to do?
Obviously, I am not going to rumble around the documentation and how to actually code and use remote events/functions. If you want to, check out the attached material above. Don’t rely on the following:
“If my code works, then it’s okay.”
What makes someone a good scripter is the fact their programming skills are not only essential (i.e. knowing how remote events work), but also knowing how to implement them into games. Obviously, exploiters are a huge bug that can make coding games a nightmare. How do exploits work? Exploits work in a fairly simple way. They allow the client to run any script they want. Lucky for us, they can only run local scripts and not server ones, so the problem is contained only to the client-side. But the client also has access to remote events and functions, meaning that they can fire them at any time and transfer all the information they want. So, how do I counter this issue?
To use a real-life example, let’s do some time traveling back to ancient Rome! Obviously, back then, people didn’t have the internet or Discord or any social media for that matter. They could only transfer messages via a real person messenger. Obviously, the messenger transferred the message in the exact words made by the sender. They didn’t have any right to alter or change the message sent by the sender. When they finally arrive at the destination palace, they transmit the wanted news to the recipient. Afterward, the recipient can receive the news and act accordingly.
Similarly, with remote facilities, the messenger (remote events/functions), should not alter any messages sent by the client. Essentially, when firing remote events or functions, you should seldomly to never pass any values, unless rendered completely necessary. Remember! Use remote events and functions wisely. For example, when making the shop, don’t check if the player has the coins on the client, and then fire the event. Don’t tell the server:
I want to buy this item.
but rather:
Can I buy this item?
The message isn’t altered whatsoever, the server receives the message, checks if the player has enough coins, and proceeds to cancel or confirm the purchase.
: Conclusion:
To conclude, remote facilities can be very dangerous and can be exploited easily to break your game’s economic system or ruin the experience for other players. I sincerely hope that you’ve gained, even minimal, knowledge regarding how remote events and functions should be properly used. Feedback is always appreciated! Let me know down below! Have a nice day, everyone!