Is there a way to share variables between two scripts

I have a script that is using a module script but i want another script to share a table that is inside the regular script. is there a way to share the table from one script to another?

1 Like

I’m not sure if this is the right answer because the way you described what you wish to achieve didn’t map 100% in my head, in particular which script does what, however if I understood it correctly you could use BindableFunctions.

BindableFunctions are my way to get things from one script to the other, where one script needs something from another script fires the bindable to get the necessary info from another script.

You could use the global variable _G.

In one script you could say:

_G.Table = {1, 2, 3, 4, 5}
In another Script, you could reference this variable like so:

print(table.concat(_G.Table, ", "))

Alternatively, you could use another ModuleScript.

1 Like

Another way could be value objects.

Though there seems to be no value obj for tables/lists.

thank you all for your replies i’ve used bindable functions and it works great

1 Like

It’s generally considered bad practice to clog the global table when you could use Bindables or ModuleScripts instead. I’d advise against doing this.

3 Likes