Can't get image id from dictionary

I can’t seem figure how to get the image id from this dictionary, no matter how many times I try i can’t get my head around it.

a small part of my code on a local script on the client for a GUI:

local contentsModule = rs:WaitForChild("SpinnerContents")
local contents = require(contentsModule)
local itemTypes = contents:GetItemTypes()

local function AddToInventory(ItemName, ItemImage, ItemColour)
	local TemplateClone  = Template:Clone()
	TemplateClone.Parent = inventoryScrollingFrame
	TemplateClone.ItemName.Text = ItemName
	TemplateClone.Image = ItemImage
	TemplateClone.ItemName.TextColor3 = ItemColour
	TemplateClone.Name = ItemName
	buttonConnections[#buttonConnections + 1] = TemplateClone.MouseButton1Down:Connect(function()
		if player.Equipped.Value ~= TemplateClone.Name then
			script.Parent.Inventory.ItemInformation.ItemImage.Image = TemplateClone.Image
			game.ReplicatedStorage.SendEquipped:FireServer(TemplateClone.Name)
		end
	end)
end

game.ReplicatedStorage.SendEquipped.OnClientEvent:Connect(function(weps)
	for i, v in pairs(weps) do
		AddToInventory() -- details from dictionary here
	end
end)

dictionary in replicated storage:

function contents:GetItemTypes()
	local itemTypes = {
		-----------------------------------
		{
		Rarity = {Name = "Common",		Chance = 0.589, 	Color = Color3.fromRGB(0,85,127)};
		Items = {
			
			{Name = "Test", ImageId = --image id would be here, i have a tester value as i haven't made any yet.
			{Name = "Test2", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Uncommon",	Chance = 0.300, 	Color = Color3.fromRGB(43,125,43)};
		Items = {
			
			{Name = "Item6", ImageId = --image id would be here, i have a tester value as i haven't made any yet.
			{Name = "Item7", ImageId = --image id would be here, i have a tester value as i haven't made any yet.
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Rare",		Chance = 0.100, 	Color = Color3.fromRGB(210,85,0)};
		Items = {
			
			{Name = "Item11", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			{Name = "Item12", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			}	
				
		};
		-----------------------------------
		{
		Rarity = {Name = "Legendary",	Chance = 0.010, 	Color = Color3.fromRGB(170,0,0)};
		Items = {
			
			{Name = "Test16", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			{Name = "Item17", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			}
		
		};
		-----------------------------------
		{
		Rarity = {Name = "Mythical",	Chance = 0.001, 	Color = Color3.fromRGB(170,0,225)};
		Items = {
			
			{Name = "Item21", ImageId =  --image id would be here, i have a tester value as i haven't made any yet.
			}
		
		};
		-----------------------------------
	};
	
	-- Records the group the item belongs to. This can be used to retreive data on the item's group (such as it's rarity, color, etc) when we only have info for the item.
	for groupIndex, group in pairs(itemTypes) do
		for i, item in pairs(group.Items) do
			item.GroupIndex = groupIndex
		end
	end
	
	return itemTypes
end

To sum it up I want to run the function AddToInventory() but I can’t seem to get the information I need from the dictionary, and also I didn’t make this dictionary I am using a modified version of this tutorial:

weps is a table of weapon names, I need to find these names on the dictionary and their image ids.

How can check if v is an item in the dictionary?

Would the first Common > Test > ImageId be:
itemTypes [1].Items[1].ImageId

I am going to assume your table is actually complete, I had to rebuild it for my tests.

In the contents module you can add this function:

function contents:GetItemByName(name :string) 
	for _,group in pairs(contents:GetItemTypes()) do 
		for _,item in pairs(group.Items) do
			if name == item.Name then
				return item
			end
		end
	end
end

now you can use something like this

--checking for items
local weaps = {"Item21","LOL","Test"}
for _,name in pairs(weaps) do 
	local item = contents:GetItemByName(name)
	if item then 
		print(item.Name,item.ImageId,contents:GetItemTypes()[item.GroupIndex].Rarity.Color)
		--AddToInventory(item.Name,item.ImageId,contents:GetItemTypes()[item.GroupIndex].Rarity.Color)
	end
end

Gives an error

After lots of trying i found the solution:

game.ReplicatedStorage.SendEquipped.OnClientEvent:Connect(function(weps)
	for i, v in pairs(weps) do
		for i, val in pairs(itemTypes) do
		local find = val["Items"]
			for i, val2 in pairs(find) do
				local name = val2["Name"]
				local imageid = val2["ImageId"]
				local rarityGroup = itemTypes[val2.GroupIndex].Rarity
				if v == name then
					AddToInventory(name,"rbxassetid://"..imageid, rarityGroup.Color)
					if name == player.Equipped.Value then
						script.Parent.Inventory.ItemInformation.ItemImage.Image = "rbxassetid://"..imageid
					end
				end
			end
		end
	end
end)