I’m currently making a module, but when it is required, and I use the :Get() method on it, it always returns nil.
This is the module scripts :Get() function basically, and it prints {“ATK” = 100}
print(allInfo[name])
return allInfo[name]
But when I try to require it by a script, it returns nil?
This is the servers code:
infoHandler:Get(profile.Data["Equipped"])["ATK"]
The server errors with "attempt to index nil with “ATK”, even though the the module script just barely printed it just fine?
The ModuleScript is placed in a folder named “Modules”, inside of replicated storage, and the normal script is inside a folder in serverscriptservice, does anyone know why this is happening?
And yes, when I try to print allInfo[name][“ATK”], it prints fine.
local initialized = false
local allInfo = {}
local InfoHandler = {}
function InfoHandler:Init()
for _, module in script:GetChildren() do
local info = require(module)
for index, thing in info do
allInfo[index] = thing
end
end
initialized = true
end
function InfoHandler:Get(name)
if initialized == false then
self:Init()
task.wait()
self:Get(name)
else
if allInfo[name] then
print(allInfo[name]["ATK"])
return allInfo[name]
else
warn("⚠️ - SHARED | "..name.." is not a valid item/creature/ability!")
end
end
end
return InfoHandler
Script:
local coins = createInt("ATK ⚔️")
coins.Value = infoHandler:Get(profile.Data["Equipped"])["ATK"] -- Line thats erroring
coins.Parent = leaderstats
The “Script” is actually just a modulescript initialization function, but its requiring fine, so that shouldn’t be the issue.
Thanks for your help, but for some reason it started to work again? I didn’t have to change any code or anything. I’m guessing it was just an issue with Roblox Studio or ProfileService returning something weird when trying to retrieve something from it.