How do I index this?

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]

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

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

You have to call require() on it, not just reference it.

5 Likes

ooops, i actually forgot that… I have been wondering for so long on why it wasn’t working…

1 Like