-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRequireOnlineModule.luau
More file actions
31 lines (22 loc) · 969 Bytes
/
RequireOnlineModule.luau
File metadata and controls
31 lines (22 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
--!optimize 2
local RequireCache = {} -- Store required ModuleScripts for further use (ModuleScript persistance).
-- Fake Require func
local function ARequire(ModuleScript)
local Cached = RequireCache[ModuleScript]
if Cached then -- If module is already loaded, return it.
return unpack(Cached)
end
local Source = ModuleScript.Source
local LoadedSource = loadstring(Source)
local fenv = getfenv(LoadedSource) -- Fake environment
fenv.script = ModuleScript -- Set script variable.
fenv.require = ARequire -- Overwrite require so it can require other modulescripts and so forth.
local Output = { LoadedSource() } -- Execute the module
RequireCache[ModuleScript] = Output -- Store module in cache for further use.
return unpack(Output) -- Return the result to the executor
end
local function ARequireController(AssetId)
local ModuleScript = game:GetObjects("rbxassetid://" .. AssetId)[1]
return ARequire(ModuleScript)
end
return ARequireController