Well, to put it simple, there're two ways you could go about this: you could use a module script, and have the main(?) script call on it, while the module script returns the set data, or you could use _G, which I highly recommend against using, as it shares across any serverside script, and does not work w/ localscripts.
This is how a module script would be set up, and how the main(?) script would call upon it:
return {
'Data'
}
local returnTableFromModule = require(MODULE)
print(returnTableFromModule[1])
To add, and note from before, the require function will call upon the module script, but also yield the code until the module script returns the code/ exists w/in the specific parent.
Now, onto _G; however, before I begin, I recommend NOT using this, as it has loopholes & security vulnerabilities, i.e. any serverside could retrieve it, localscripts can not communicate w/ it, and any serverside script could edit/ alter the data (at will), so if an exploiter wanted to edit the data at any time, it's free for the taking to edit/ alter.
This is how it would be set up, incase you're curious:
_G.Data = {
'Data'
}
print(_G.Data[1])
_G.Data = {
'Altered Data'
}
print(_G.Data[1])
More information about what was mentioned
_G - I recommend AGAINST using this.
Module Scripts - I highly recommend this over _G, as it has better security, and is safer for script to communicate through, + I believe localscripts can access this (however, I can not confirm this, so if you plan on doing this, proceed w/ care).
Stuff touched on, but didn't go into great detail about
The Require Function
Hope this helped you in any way! :D
5 comments
Exploiters cannot add scripts to the server, can they? My impression is that they only have control over the client (though if you don't have FilteringEnabled on, I suppose they could...). And, if they do have control over the server, it doesn't matter whether you use _G or ModuleScripts, an added script can easily read from both locations. ModuleScripts are still better, as LocalScripts can use..
...the code. Of note, all server-side scripts have access to the contents of the ModuleScript, the same as _G. The ModuleScript only runs once (for the server).
@chess123mate Ah, alright; ty for letting me know. :) As to exploiters controlling the client, I always believed they both messed w/ the client & server, buuut that seems to be wrong. XP
lol it seems I really tripped up here; please forgive me. XD
Um, well, tyvm for accepting my answer. XD