28Y8
(28Y8)
March 22, 2020, 4:52pm
#1
I have been trying to print the value 100, but it can’t index it. What should I do?
Module;
local UpgradeModule = {
Location = {
Upgrade = {
Cost = {"Money", 100}
}
}
}
return UpgradeModule
How I indexed it;
local a = "Location"
local b = "Upgrade"
print(UpgradeModule[a][b].Cost[2])
Error:
[17:46:02.914 - Location is not a valid member of ModuleScript]
snorebear
(snorebear)
March 22, 2020, 4:54pm
#2
Make sure you use the require
statement for module scripts before utilizing the object. After you require it, you should be able to use your above code. If it still doesn’t work after that, shoot me a reply.
1 Like
28Y8
(28Y8)
March 22, 2020, 4:55pm
#3
It has been required further up in the code, but I haven’t posted it.
local UpgradeModule = game.ReplicatedStorage.Assets.Modules.ItemData:WaitForChild("UpgradeModule")
The code you’ve shown us seems like it should work, so the error is probably somewhere else. Can you show the stack trace of the error you provided?
1 Like
rogchamp
(pasta)
March 22, 2020, 4:56pm
#5
You have to call require()
on it, not just reference it.
5 Likes
28Y8
(28Y8)
March 22, 2020, 4:57pm
#6
ooops, i actually forgot that… I have been wondering for so long on why it wasn’t working…
1 Like