Hi! I was using module loaders for the first time, and I noticed that when you call ModuleLoader:Get(), IntelliSense doesn’t provide autocomplete suggestions. Does anyone know how to make IntelliSense recognize the returned module?
Also, is there a way to enable IntelliSense support for a shared variable as well?
I mean, when I retrieve a cached module using the Get function, intellisense doesn’t work.
--!strict
--// Services
local RunService = game:GetService("RunService")
--// Constants
local SERVER = "Server";
local CLIENT = "Client";
local BOTH = "Both";
--// ModuleLoader
local ModuleLoader = {}
local CachedModules = {}
function ModuleLoader.Get(name: string)
return CachedModules[name];
end
function ModuleLoader._init(scripts: {Instance})
for _, module in scripts do
if (not module:IsA("ModuleScript") or module == script) then continue; end
local runContext: string = module:GetAttribute("RunContext") or BOTH;
if (runContext == SERVER and RunService:IsClient()) or (runContext == CLIENT and RunService:IsServer()) then continue; end
local mod = require(module);
CachedModules[module.Name] = mod;
end
end
function ModuleLoader._start()
for _, module in CachedModules do
if (typeof(module) == "table") then
local init: () -> () = module._init;
if (init) then
task.spawn(init, module);
end
end
end
end
return ModuleLoader;
This has no reason to work at all, never will.
The CachedModules dictionary gets setup at runtime, not in edit mode, thats why you are not getting autocomplete.