simple answer, no you can’t
when roblox runs its “autocomplete magic,” it simply doesn’t run any runtime code, it just evaluates what it “thinks” things would be
for example
local module = {}
--v is inferred to be of an Instance type
for i, v in script:GetChildren() do
if v:IsA("ModuleScript") then
--because v is an Instance type
--require(v) is then inferred to be an "any" type
--v.Name is also inferred to be a "string" type
module[v.Name] = require(v)
end
end
return module
that is what Roblox sees
but, you showed you can autocomplete if you write every module seperately
you can make a plugin to do this task, all it would do is fill in the absolute path to generate the modulescript’s source
for example
function GenerateModuleListFor(inst)
local Source = "local Module = {"
for i,v in pairs(inst:GetDescendants()) do
if v:IsA("ModuleScript") then
--could use string.format but im too lazy
Source ..= v.Name.. "=require(".. v:GetFullName().. "),"
end
end
Source ..= "} return Module"
return Source
end
although you do know it would require you to re-make the module list whenever a module
but just know the main drawback of the system is that all of the modules are dependants of the main module, which means you can’t require the main module at all in any of the modules that are children to it.
you could get around the issue above by using metatables
--trick autocomplete using this type
--(it would have to be generated using a plugin like shown above)
export type Modules = {
Farter: typeof(require(script.Farter)),
Stinkalizer: typeof(require(script.Stinkalizer)),
}
--assign GlobalModules as type Modules
local GlobalModules : Modules = setmetatable({}, {
__index = function(self, moduleName)
local module = require(script:FindFirstChild(moduleName))
GlobalModules[moduleName] = module
return module
end,
})
return GlobalModules
but the main issue with global modules, and probably why roblox hasn’t implemented them is because its hard to tell what the dependants of a script or modulescript is
local Modules = require(game.ReplicatedStorage.Modules)
--^^theres no indication of what modules specifically this script needs
--imagine the lines below are buried in a 700+ line script
Modules.Farter.DoSomething()
Modules.Stinkilizer.DoSomething()
but with roblox’s current bread and butter module system it’ll look like this
local Farter = require(game.ReplicatedStorage.Farter)
local Stinkilizer = require(game.ReplicatedStorage.Stinkilizer)
--^^ now we know exactly what this script needs!
--we know that if we remove all other modules, if we have these two then this script works
--imagine the lines below are buried in a 700+ line script
Farter.DoSomething()
Stinkilizer.DoSomething()
basically, if you need to make a global modulescript, you can using the way i showed, but if you can avoid it, its good coding practice. your future self (and other co-contributers) will thank you