How to find if a value in a table exists

Hi, I have been trying to find out how to check if a value in a table exists

I have tried

if Upgrades[upgradeName][amountBought]["Cost"] then

which didn’t seem to work, it will just bring up this error
ServerScriptService.MainModule:51: attempt to index field '?' (a nil value)

any suggestions on how to fix the issue?

Full function:

function module:GetUpgradeCost(player, upgradeName, amountBought)
	if Upgrades[upgradeName][amountBought]["Cost"] then
	return Upgrades[upgradeName][amountBought]["Cost"]
	else
	return "MAXED"
	end
	end

As the error said, it returned nil, so you’ll know that it exists or not with

if upgradeName ~= nil and amountBought ~= nil then
3 Likes

Thank you that did the job well.