Get 3 sets of boxes to be filled in with appropriate items

if toyData.Materials == 1 then
		if toyData.Wool > 0 then
			toyFrame.First.Quantity.Text = toyData.Wool
		end
		if toyData.Wood > 0 then
			toyFrame.First.Quantity.Text = toyData.Wood
		end
		if toyData.Metal > 0 then
			toyFrame.First.Quantity.Text = toyData.Metal
		end
		if toyData.Fleece > 0 then
			toyFrame.First.Quantity.Text = toyData.Fleece
		end
	end
	if toyData.Materials == 2 then
		if toyData.Wood > 0 then
			toyFrame.Second.Quantity.Text = toyData.Wood
		end
		if toyData.Metal > 0 then
			toyFrame.Second.Quantity.Text = toyData.Metal
		end
		if toyData.Fleece > 0 then
			toyFrame.Second.Quantity.Text = toyData.Fleece
		end
	end
	if toyData.Materials == 3 then
		if toyData.Metal > 0 then
			toyFrame.Third.Quantity.Text = toyData.Metal
		end
		if toyData.Fleece > 0 then
			toyFrame.Third.Quantity.Text = toyData.Fleece
		end
	end

ModuleScript

toys.Data  = {
	['Teddy Bear'] = {
		['Level'] = 1,
		['Materials'] = 1,
		['Wool'] = 2,
		['Wood'] = 0,
		['Metal'] = 0,
		['Fleece'] = 0
	},
	
	['Ball'] = {
		['Level'] = 1,
		['Materials'] = 1,
		['Wool'] = 3,
		['Wood'] = 0,
		['Metal'] = 0,
		['Fleece'] = 0  
	},
	
	['Yo-Yo'] = {
		['Level'] = 2,
		['Materials'] = 2,
		['Wool'] = 1,
		['Wood'] = 2,
		['Metal'] = 0,
		['Fleece'] = 0  
	},
	
	['Slinky'] = {
		['Level'] = 3,
		['Materials'] = 1,
		['Wool'] = 0,
		['Wood'] = 3,
		['Metal'] = 0,
		['Fleece'] = 0  
	},
	
	['Drum Set'] = {
		['Level'] = 5,
		['Materials'] = 2,
		['Wool'] = 3,
		['Wood'] = 5,
		['Metal'] = 0,
		['Fleece'] = 0  
	}
}

The Materials number inside the module script is to determine how many materials each toy would need (so Teddy bear only uses the wool material, while the yoyo uses wool and wood, so 2 materials. The problem I am having is I have 3 boxes. In each box it would show what materials would be needed to make the item. So if its only 1 material, then the first box would be for that one particular material. The problem arises when it’s 2 or more materials. I don’t know how to get it to fill in the first box with the first material then move onto the second material

1 Like

You can just iterate through the table, count how many keys have non-zero values and then use that value to set materials.

Can you elaborate a bit more on the question? If I’m understanding correctly, you have 3 TextLabels that report how many materials you need to make the object, and you want to dynamically set that based on toy.Data, correct?

The way you are trying to do it right now is quite hard coded and is not going to be able to scale up, what if you add new toys that need more than three materials to craft? You already have a Drum Set toy that requires four materials.

So I suggest using a UI Layout to handle the box positioning and just inserting a new box when you encounter a non zero material requirement when iterating over the object materials.

1 Like

The Drum Set toy only uses 2 materials. No toy will use all 4 materials, max will be 3.