Way to clear ModuleScript cache

I’m sure everyone who uses ModuleScripts extensively can relate to wanting to have a way to clear the cache.
I mean sure, if you have a table returning function, you’ll just get a new table from the module, but if you’re just returning a table, the next time you load the same module it will return the exact same bs from cache.

Lua has “package.loaded.modulename = nil” for removing a module from the cache, why shouldn’t roblox?

1 Like

I feel like this would break a modulescript’s expected behavior
What happens if you delete a modulescript? If you still need it you could replace it with a clone?

No, this is super exploitable. Just make one that doesn’t cache

Turn

--- return stuff
into

[code]return function()

return stuff
end[/code]

and

stuff = require(thing)

into

stuff = require(thing)()
1 Like

Care to elaborate?

Having ModuleScripts act as singletons is actually super valuable, and I’m really happy they act like that. If you want to return a new version of whatever it is, use a function. For instance:

-- Module:
local Foo = {}
function Foo.new()
   local foo = {}
   return foo
end
return Foo

-- Script:
local Foo = require(FooModule)
local foo = Foo.new()
1 Like

[quote] Having ModuleScripts act as singletons is actually super valuable, and I’m really happy they act like that. If you want to return a new version of whatever it is, use a function. For instance:

[code]
Module:
local Foo = {}
function Foo.new()
local foo = {}
return foo
end
return Foo

Script:
local Foo = require(FooModule)
local foo = Foo.new()
[/code] [/quote]

What if someone(me) had over 70 modules each returning tables and after a long time realized I needed “new tables” every time I required the modules.

I know that’s just my own stupidity, but there are plenty of uses for this, surely if no-one needed it, Lua didn’t have a way to clear the cache.

Care to elaborate?[/quote]

If a player clears the cache then all your scripts break

thing = require(Module:Clone())

Magical.

12 Likes