How do I insert a ModuleScript in a ModuleScript?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to have it without indexes. And without overwriting old data. EX:
local tbl = {
	["Hello, World"] = "function",
	["Hello, World2"] = "function", -- stuff from other ModuleScript
}
  1. What is the issue? Include screenshots / videos if possible!
    Is this possible? At all? If so how?

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

table.insert(tbl, require(script.ModuleScript))

returns

local tbl = {
	["Hello, World"] = "function",
	[1] = {
		["Hello, World2"] = "function", -- stuff from other ModuleScript
	}
}

Maybe This?

table.insert(tbl, {Module = require(script.ModuleScript)})
tbl.Module = require(script.ModuleScript)

That still made indexes and made a new dir.

local tbl = {
	["Hello, World"] = "function",
	[1] = {
		["Hello, World2"] = {
			["Hello, World2"] = "function"
		}
	}
}

Try:

for _, Module in pairs(script:GetChildren()) do
    tbl[Module.Name] = require(Module)
end

Let me know if this works or not!

1 Like

Works, but not what I’m looking for. It makes a new directory with the module name. I don’t want that. I need it to insert the functions from the module into the table without creating another directory. like:

local tbl = {
	["Func1"] = "function",
	["Func1"] = "function", -- stuff from other ModuleScript
}

Hmmm, maybe:

for _, Module in pairs(script:GetChildren()) do
    table.insert(tbl, {
      Module.Name,
      Module.functionname
})
end

Not too sure about how this one will turn out.

Still indexes with 1 and so on

You can accomplish this by simply iterating the sub module script you have.
Here is an example:

for Name, Function in pairs(require(script.ModuleScript)) do
    tbl[Name] = Function
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.