Associating multiple values with a single key in a dictionary

Basically, I’m trying to store an array in a key in a dicitionary, but whenever I check the length of the array it shows up as 0 with no values instead of 3.

Show us the code so we can understand what you’re talking about.

Here’s how you should be doing it (from what your explanation says)

local dictionary = {
	
}

dictionary["Tab"] = {"Value1", "Value2", "Value3"}

print(#dictionary["Tab"])
1 Like

Can you provide the code?

sksks 30 character minimum

Yes, give me 5 minutes as I have to screenshot the client and the server.

Don’t screenshot. Instead, copy and paste it here. Make sure to format it surrounded with ``` so it highlights!

CLIENT

for i,v in pairs (orderingFrame.border.optionsScroller:GetChildren()) do
	if v:IsA("TextButton") then
	v.MouseButton1Down:Connect(function()
		if #chosen < 5 then
		orderingFrame.choices:FindFirstChild("item".. tostring(#chosen + 1)).Text = v.Name
			orderingFrame.choices:FindFirstChild("item".. tostring(#chosen + 1)).Visible = true
		table.insert(chosen,v)
		else print("too many items!")
		end
	end)
	end
end

SERVER

	if event == "destroy" then
		plr.PlayerGui:FindFirstChild("orderingSystem"):Destroy()
	end
	if event == "claimOrder" then
	local order = findOrder(info1)
	plr.makingOrderFor.Value = info1
	plr.isMakingOrder.Value = true
	if order then
		
		order.status.Green.Visible = true
	
		order.status.Red.Visible = false
		
		order.status.Text = "CLAIMED"
	
		updateBoardForAll()
	
	end
	end
end)

later in the script

if  playerHasAllItems(secondplayer,itemsNeeded) then
		
		firstplayer.makingOrderFor.Value = ""
		firstplayer.isMakingOrder.Value = false
		removeItemFromTable(orders,secondplayer.Name)
		findOrder(secondplayer.Name):Destroy()
		updateBoardForAll()
		end

“the playerHasAllItems function”

function playerHasAllItems(plr,array)
	local missingOne = false
	print(#array)
	for i = 1,#array do
		if plr.Backpack:FindFirstChild(tostring(array[i])) then
		else
			missingOne = true
		end
	end
	if missingOne == true then return false
	else
		return true
	end
end

Was the # in (#dictionary[“Tab”[) a type? Because that’s probably the problem then.

Not too sure what you mean by Type, # just prints the length…

Does it need to be in that format for it to be printed correctly?

From what I am aware yes, it really depends on your method.

what is the problem on wiki you can read dictionary can have any data type so

local d = {
[“key”]={“value1”,“value2”,“value3”}
}
and find it by
local resultd=d[“key”]
local result1=resultd[1]
local result2=resultd[2]
local result3=resultd[3]

The unary length operator # doesn’t work on a dictionary because your entries are stored in the table’s hash. The only time the operator works is when you’re using numerical indices for a dictionary, which is the equivalent of just making an array.

For example:

local library = {
    ["dict1"] = {"v1", "v2", "v3"}
}

#library will give 0, but #library.dict1 will give 3.