Skip to content

Require Online Module

htt-py edited this page Sep 16, 2023 · 1 revision

Or Shortly ROM ARequire stands for Artificial Require

Source Code

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 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 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

Usage

local FileName = "RequireOnlineModule"
local ARequire = loadstring(
	game:HttpGet("https://raw.githubusercontent.com/luau/SomeHub/main/" .. FileName .. ".luau", true),
	FileName
)()
local ModuleOutput = ARequire(2780820589) -- 2780820589 is AssetId for an online Roblox module that's been uploaded to the Creator Marketplace Library, ARequire works similar to require
print(ModuleOutput)

Test Siderbar

Clone this wiki locally