I am attempting to write a function that runs once to compile a large collection of modules into a single reference table. The reason I need to do this is to get another piece of code to operate efficiently without looping through every single time.
I am able to get values from the looped modules, but whenever I try to insert them into my reference table, they refuse to go. I created a pcall to see if there’s some kind of formatting issue, and the pcall just errors out with table index is nil.
Build Function
mod.RegModuleReference = {}
mod.BuildModuleReference = function()
for i,module in pairs(cm.reg:GetChildren()) do
if module:IsA("ModuleScript") then
local thisModule = require(module)
print(module.Name.." "..thisModule["groupId"])
print("\n")
print("MODULE REFERENCE: Located module: "..module.Name)
local success, errorReason = pcall(function()
table.insert(
mod.RegModuleReference,1,
{
[thisModule["groupId"]] = {
1
}
}
)
end)
if not success then
error(errorReason)
end
print("MODULE REFERENCE: Inserted values from: "..module.Name)
local testIndex = table.find(mod.RegModuleReference,"purplepeopleeater")
print(testIndex)
print(mod.RegModuleReference)
end
end
end
Edit 1: Error was resolved, but inserting into the reference table is still broken.