Where I asked that if I had some ModuleScript that, I don’t know… it calls another ModuleScript that returns a value uhhh…
Well, I wasn’t able to get a updated result when reloading that specific module.
Then recently I found out that you can use require() and provide it with an AssetID. This then will attempt to load a Model but specifically look for a ModuleScript called “MainModule”.
So you can do require(assetid) and yeah. Thing is, when you update this Model with the “MainModule”, using require(assetid) with the same assetid, won’t load the updated version.
I have to restart Studio or the game incase I used require() while starting the game.
So, I started thinking on why that would be so.
And the Lua docs say that require, well Lua’s native require has a control table, that is accessible through a global value called _LOADED, so something similar like _VERSION
just that _LOADED doesn’t seem to be accessible, and I was looking for a way that does a complete reload on everything that was done with require
The library asset needs to be named ‘MainModule’ not ‘MainScript’.
Additionally, the ‘loaded’ table is not provided by Luau, you could emulate its behavior by having a script require every ModuleScript and packing all of the return values within a single dictionary (module names as keys/fields and their contents as the respective values).
It’s not a bug, the entire ‘package’ library which is native to Lua has been omitted from Luau.
Hence why the package.loaded, package.preload and package.searchers tables are not defined.
In native Lua package.loaded contains a cache of the loaded modules, package.preload contains user-defined functions for loading modules and package.searchers contains ‘searcher’ functions that are used to locate a suitable ‘loader’ function for the required module.
Oh my bad, I wasn’t sure what you were referring to. This is a fairly well documented issue.
The work around is to just launch a testing session of the game, or delete the ModuleScript and re-create it. Another approach is to convert the module into a constructor function which returns an object that inherits all of the module’s functions and properties.
local Module = {}
function Module.new()
return setmetatable({}, {__index = Module})
end
return Module
Each call to Module.new() will return a new object that inherits the module script’s contents.