Hi, so im making a crafting system and the problem im having is im not sure how to get it to loop through the table and get all the required resources before you are able to craft an item.
CraftItem.OnServerInvoke = function(player, item)
local Inventory = player.Inventory
for i,v in pairs(CraftingRecipe[item]) do
if Inventory:FindFirstChild(i) then
local Material = Inventory:FindFirstChild(i)
if Material then
if Material.Value >= v then
Material.Value = Material.Value - v
if Inventory:FindFirstChild(item) then
Inventory[item].Value = Inventory[item].Value + 1
else
local AddItem = Instance.new(“NumberValue”, Inventory)
AddItem.Value = 1
AddItem.Name = item
end
end
end
end
end
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.