Problem with tables

Hello, I can’t figure out how to access my variables that are inside of a table.

researchitems = {
	["Label"] = {
		level = 1,
		cost = 15
	}
}

function checkLevel(obj)
	for object, params in pairs(researchitems) do
		if object == obj then
			local level = params[1]
			return(level)
		end
	end
end

function checkCost(obj)
	for object, params in pairs(researchitems) do
		if object == obj then
			local cost = params[2]
			return(cost)
		end
	end
end

game.ReplicatedStorage.Research.OnServerEvent:Connect(function(player, object)
	local level = checkLevel(object)
	local cost = checkCost(object)
	print(level, cost)
end)

It prints nil as the level and cost, i can’t figure out why.

researchitems = {
	["Food"] = {
		level = 1,
		cost = 15
	}
}

function checkLevel(obj)
	for object, params in pairs(researchitems) do
		if object == obj then
			local level = params.level
			return(level)
		end
	end
end

function checkCost(obj)
	for object, params in pairs(researchitems) do
		if object == obj then
			local cost = params.cost
			return(cost)
		end
	end
end
1 Like

Is object an instance? If so, then you should do obj.Name.

The object is a string its just the name of something

Try to debug and print something after the line where if you check if the obj is the same as object.