Please enable debug.loadmodule so that I can reload modules

As a Roblox developer, it is currently too hard to cleanly hot reload modules

This is where I can load a module, change its sourcecode slightly, and reload it again with the new sourcecode, this isn’t possible with require since require caches the return of the module.

In most usecases, this is fine and expected behaviour, but in some usecases (most notably, component development with UI frameworks), it would be nicer if I could just flush the cached value and re-run the script.

The engine already has a function that acts as an alternative to flushing the return cache, its called debug.loadmodule, but its disabled behind the flag DebugEnableLoadModule. This function compiles the module, then returns the main prototype of a module. This can then be called with variadic arguments (or none), and respects changes in the source code.

This feature request suggests enabling it as, it would improve my development experience because I can then develop modules without needing to cut and paste them back in

29 Likes

Yes please, I am suffering the same thing, I wanna test the module without getting in the game, but i can’t test those changes live because there is no way to reload script unless you copy and replace it.

Before saying Reload Script button exists, it doesn’t work. I tried.

This would be really good debugging tool to have in overall so. Big support.

2 Likes

It’s not quite clear from your post – are you referring to reloading modules in Studio edit mode (and test sessions)?

2 Likes

He means that when you use require() on a modulescript, if it’s done the first time, it will execute the script, return the result and from now on only return that result (AKA cache the result).
debug.loadmodule() would circumvent caching and force to execute the module to get the result.
Basically. require() when first time use on a module, the result is computed and then stored (as modules execute only once). While debug.loadmodule() will ALWAYS execute a module and return the result regardless if it already was executed or not.

5 Likes

ive ran into this issue as well in the past though i’ve made a habit to dump all the requires needed inside of the component’s init (or render if you’re using roact-hooks/roact17) while im developing UI and move them out of it once I’m done. Though debug.loadmodule would be a lot more user friendly than going down that route.

2 Likes

bump this is pretty useful because i used it after patching studio (would be cool if they enabled it for game devs without having to change fast flags)

1 Like

Oh my god yes, this is something that has bothered me a LOT too.
Happened to me while I was working with OOP, I often found myself having to fully restart my playtest to perform any sort of changes to class modules due to reloading doing nothing. Really REALLY need this feature.

2 Likes

This function works in studio [ONLY].
I’m not sure what 3 arguments it returns, but maybe you can hot reload modules
image

Also roblox removed it from debug type
image

I forgot to say, I actually suggested this at RDC.

The engineers said that this can be something they can fix.

They could make the Reload Script button on modules invalidate its cache and all scripts would re-require it.

I’m not sure entirely anymore what they said they would do. But I remember it was positively received and would probably be fixed sometime!!

1 Like

I need a programmatic way of doing this, a Reload script button doesn’t solve this issue.

1 Like

never got a problem to reload a module however it seems important to some people so cant they just add

ModuleScript:Refresh() – on next require scripts inside get executed again

LocalScript:Reload() – runs the script again
Script:Reload() – same thing

this doesn’t seem difficult on a technical level from my standpoint and a loadstring being the only workaround that i know is absolutely criminal

1 Like