What’s to feel weird about? The point of require is to get the return value of a module. If it reran its entire code every time, it would be slower, more memory inefficient, and less useful to developers.
I do this in Studio a fair bit! When I’m testing modules from the command line, I often use my own ‘unique require’ function to make sure Studio doesn’t cache the return value and runs the most up to date version of the code.
Here’s the implementation:
local function urequire(module)
assert(typeof(module) == "Instance" and module:IsA "ModuleScript", "urequire only works with module script instances")
-- create copy of module
local newModule = module:Clone()
-- swap module with cloned version
newModule.Parent = module.Parent
module.Parent = nil
-- run module
local value = require(newModule)
-- put old module back and destroy cloned module
module.Parent = newModule.Parent
newModule:Destroy()
-- done
return value
end
This code will replace the module script with a cloned version, require the newly cloned version, then put the old module back, and return the values from require().