Make one ModuleScript access all the contents of its children

So basically im trying to make a main ModuleScript that acccesses every other ModuleScript which has Data of enemies stored inside of it. Here’s an example of it:

So basically the Library ModuleScript accessess all the modulescripts inside and can check the Data.
For Example:

Enemy 1 script for World 1 has data like:

local module = {
	["Name"] = "Grass Entity";
	["Health"] = 200;
	["KillReward"] = 150;
	["World"] = "World 1";

return module

and then the Library ModuleScript accessess it and sends it to the server/client.


use script:GetDescendants() and script.DescendantAdded to load your module data.

local Library = {}

local function onDescendantAdded(ins:Instance)
	if ins:IsA("ModuleScript") then
		if not Library[ins.Parent.Name] then Library[ins.Parent] = {} end
		Library[ins.Parent.Name][ins.Name] = require(ins)

for _, ins in script:GetDescendants() do

return Library
1 Like

So a module loader? What are you talking about here, are you trying to use SSA (Single-Script Architecture?) If you are just trying to get that module to run, parent it to a script and require it in the normal script.

I’m pretty sure double brackets like that assumes you’re refrencing an index that already exists.

Basically just require the ‘Library’ ModuleScript and you can then find the data of the modulescript based on the World or Name of the Enemy

I guess its kind of like a FrameWork. Im also adding like ModuleScripts with functions to it.

Kinda pointless to store each enemy data as a separate module rather than using shoving all the data inside a World module since the data aint that big either but anyways, u could just make a World1 a module too which returns all enemies

-- World 1
return {
   Enemy1 = require(script.Enemy1)

-- Library
return {
   World1 = require(script.World1)

-- Another module

Im barely just using this as an example. The ModuleScripts are gonna have lots of functions/data stored inside them

This is one of the reasons im trying to use a ModuleScript to find the ModuleScript of the enemy and then access all of its other data.
Basically the ModuleScript having another data

local module = {
	["Name"] = "Grass Entity";
	["Health"] = 200;
	["KillReward"] = 150;
	["World"] = "World 1";
	["ClassType"] = "Enemy";

return module

Basically the Library module would go through the ModuleScripts and look for the ClassType and then accessess all the other data.

I also got a place copy of My Restaurant which I’m using ONLY for education and learning how some systems work. I also saw that they were using some kind of ‘Framework’ like this.

You could do that but you would lose out on intellisense so its better to just explicitly return each enemy data

This is how the Framework looks and I’m kind of looking to replicate this kind of scripting.
It’s kind of complicated since I’m not familiar with this type of scripting and I’m basically looking for an explanation/tutorial on how these types of systems work.

The module names are real iffy bro :sob: you def gonna lose out on intellisense with all em spaces and bars and numbers

anyways real talk u really dont need the numbers and the “|” and the “CUSTOM” just name them Directory, Variables, Services, Shared, Network, Audio and u good

The one im currently showing is from the game ‘My Restaurant’ and it uses a system like this.

Another post talked about something close to this. This is basically what i want to achieve with my modulescript.

There would be an enemy. I kill it and once i kill it a script fires a function that looks for the enemy inside the Library kinda like:

--Pretend the ModuleScript of the enemy has an array called 'ClassType' with the class being 'Enemy'
_L["ClassType"] --find the modulescript with the classtype and does some stuff like reward the player

You might want to change the titles of the scripts