How to get the name of an element in a dictionary

This code cycles through a dictionary of dictionaries to find the dictionaries that have elements in them. An example of a filled dictionary would be ["Bucket"] = 1 in dictionary v. How would I get the script to print [“Bucket”] instead of just 1? I need both parts in order to map the inventory I’m making correctly.

game.ReplicatedStorage.Inventory.MapInventory.OnClientEvent:Connect(function(Inventory)
	local CurrentItem
	for i,v in pairs(Inventory.Data) do
		for a,b in pairs(v) do
			if b then
				--Issue here
			end
		end
	end
end)
1 Like

Just print the index.

Code:

game.ReplicatedStorage.Inventory.MapInventory.OnClientEvent:Connect(function(Inventory)
	local CurrentItem
	
	for i, v in Inventory.Data do
		for a, b in v do
			if b then
				print(a)
			end
		end
	end
end)

Pairs is also useless as Roblox added generalized iteration which performs faster.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.