Roblox Require (Import Module)

Is there a way like in JS, that we can like local a, b, c = require(folderpathtomodules)
and after that it require all the modules inside folderpath

You can create a function to emulate this behavior, but Roblox does not natively support this.

local ReplicatedStorage = game:GetService ("ReplicatedStorage")

function RequireFolder (folder)
	local modules = {}
	
	for _,v in pairs (folder:GetChildren ()) do
		if v:IsA ("ModuleScript") then
			table.insert (modules, require (v))
			
		end
	end
	
	return table.unpack (modules)
end

local a, b, c = RequireFolder (ReplicatedStorage.Modules)
1 Like