How to transfer info server-server?

Basically, I have 2 server scripts. I wanna transfer information from 1 to the other. How can I do this?

You have several different ways to do this:


BindableEvents and BindableFunctions were created to allow scripts to implement custom events and event handling behavior. Unlike RemoteEvents/Functions, these instances do not cross the client/server boundary and are perfect if you need to invoke some behavior in another script.

Note data sent through BindableEvents/Functions are serialized, so table reference identity is lost. In other words, tables sent through these instances come out the other side as entirely new tables. Additionally, note the other restrictions.

Value Instances / Attributes

Instead of storing values that must be shared as pure Lua values, you can instead place them in the Roblox Datamodel via the use of value instances or attributes. Value instances are instances that literally have a “value” field that can be modified. Here’s an example.

The Attributes API is somewhat new, and it allows you to tag custom data on instances directly instead of having to create a child Value instance. Read about it here.

ModuleScript Tables

Modulescripts can return tables whose values can be mutated by multiple scripts.

DISCLAIMER: Multiple Scripts Can Be a Bad Idea

Multiple executing scripts that share information, if done poorly, can lead to many hard-to-debug issues. Global values that can be modified by any code is dangerous because you can run into issues where scripts can “step” on one another by overwriting values at unexpected times. Basically, the more independent coroutines your game has, the more careful you have to be that each coroutine will not interfere one another.

You can read more about architecting your project here.

Whenever you have data in a program, you should always ensure that there is a “single source of truth.” In other words, all important values should have a single place where they are stored, and they should usually have only one client that modifies them.

A Solution: Game Frameworks

Game frameworks can help you build a complex application using only a single script. My favorite is Knit, but there are many open source frameworks, so be sure to check out #resources:community-resources to explore your options.

1 Like

Bindable events and Bindable functions.

Thanks! I will try out the bindables.