Hi there, I’m managing all my threads into a table where I can monitor. The issue is, is that the module table I am adding to, doesn’t change when I require it in another script. The __newindex
function works as print self[idx] doesn’t print nil, and printing self[i] also doesn’t print nil.
From ModuleScript | Roblox Creator Documentation
ModuleScripts run once and only once per Lua environment and return the exact same value for subsequent calls to require.
So, what would be the workaround for this?
I have never worked with the object-orientated and metatable stuff before, so there may be a better method.
One potential method I can think of is to have a folder in server storage, then within that folder a thread for each thread. In each thread put whatever it is that is running in that thread. This will not work if you are having functions stored for each thread though.
If the above doesn’t work and no one can come up with another method, _G may be of use, but know that you may accidently overwrite something internal so make sure you use a unique name for it
edit: Another method you could use is have the values stored in a ServerScript (instead of a module script), and have it return the table / modify the table using a BindableFunction
I did consider using _G, however this could be a huge vulnerability as scripters in my game could change those variables (even sandboxing it). I guess the best approach here would be using a bindable function as such.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.