I’m honestly just trying to require a lot of modules without it being that messy long chunk at the top of the file/module script, so I was just curious whether or not you could type check specific modules.
Make it so when you put in a certain method like :HurtCharacter, you’ll immediately get re-directed to the module with that actual method and not get an error that it doesn’t exist in said module.
for _, v in Modules.Combat:GetChildren() do
if v:IsA("ModuleScript") then
moduleCached[v.Name] = require(v)
end
end
You can make use of Roblox’s built-in type annotations and tools like Roblox LSP (Language Server Protocol) which can help provide IntelliSense support.
Define the types for your module:
-- CombatModule.lua
local CombatModule = {}
type CombatModule = {
HurtCharacter: (character: Instance) -> ()
}
function CombatModule:HurtCharacter(character)
-- Implementation
end
return CombatModule
Create a module to cache your modules:
-- ModuleCache.lua
local Modules = script.Parent.Modules
local moduleCached = {}
for _, v in Modules.Combat:GetChildren() do
if v:IsA("ModuleScript") then
moduleCached[v.Name] = require(v)
end
end
return moduleCached
Use type annotations when requiring the cached modules:
-- MainScript.lua
local moduleCached = require(script.Parent.ModuleCache)
local CombatModule: CombatModule = moduleCached["CombatModule"]
CombatModule:HurtCharacter(someCharacter)