How to get child of table in table?

So I’m trying to get the price of the index “Rig”, I’ve tried this:

local price = upgradeModule.Upgrades[button.Parent.Name].Npcs[player.Values.NpcUpgrade.Value].Price

But then I’ll get an error that it doesn’t know what price is

upgrades.Upgrades = {
	["MoneyMultiplierUpgrade"] = {["Price"] = 0.5,["Exponent"] = 1.3},
	["NpcUpgrade"] = {
		["Npcs"] = {
			["Rig"] = {["Price"] = 15,["Multiplier"] = 3},
			["Bacon"] = {["Price"] = 215,["Multiplier"] = 15},
		},
	}
}
1 Like

Access the upgrades then the NpcUpgrade then the NPCs then the name of the NPC then the price.

local price = upgradeModule.Upgrades["NpcUpgrade"].Npcs[npcName].Price
print(price) -- should print the price

You might also be getting the error if there is capital/small letter difference from the titles or paths.

1 Like

Is this a module? Looks like it too me …

local upgradeModule = require(Wherever.UpgradeModule)

local function getPrice()
    local price = upgradeModule.Upgrades["NpcUpgrade"]["Npcs"]["Rig"].Price
    print("Price of Rig:", price)
end

getPrice()

Module Script (UpgradeModule)

local upgrades = {
    Upgrades = {
        ["MoneyMultiplierUpgrade"] = {["Price"] = 0.5, ["Exponent"] = 1.3},
        ["NpcUpgrade"] = {
            ["Npcs"] = {
                ["Rig"] = {["Price"] = 15, ["Multiplier"] = 3},
                ["Bacon"] = {["Price"] = 215, ["Multiplier"] = 15},
            },
        },
    },
}
return upgrades

That’s what I’m doing, but I don’t know the name I only know the position of the npc in the table