Hello, I am making a survival game and it has a crafting table. I found a way to make it function but I believe there could be an easier way, let's say I could make recipes within an array. Is this possible?
Current code [LocalScript]
local sl1 = script.Parent.Slot1.Item local sl2 = script.Parent.Slot2.Item local sl3 = script.Parent.Slot3.Item local sl4 = script.Parent.Slot4.Item local result = script.Parent.ResultImage local ingreds = { "Sticks", 'Logs', 'Rocks', } while wait() do --CraftingTable if sl1.Value == ingreds[1] and sl2.Value == ingreds[1] and sl3.Value == ingreds[1] and sl4.Value == ingreds[1] then result.Image = 'http://www.roblox.com/asset/?id=151913757' else result.Image = '' end ------ end
Not sure if this is gonna work... but it could be made like that
local slots = {script.Parent.Slot1.Item.Value,script.Parent.Slot2.Item.Value,script.Parent.Slot3.Item.Value,script.Parent.Slot4.Item.Value} local recipes = { ["campfire"] = {"sticks","sticks","sticks","sticks"}; ["baseball bat"] = {"rocks","logs","logs"}; } for thingThatWillBeCrafted, ingredients in pairs(recipes) do for i = 1, #ingredients do if slots[i] == ingredients[i] then done[i] == true end end if #done == #ingredients then print("crafted ".. thingThatWillBeCrafted) else print("nothing") end end