Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there an easier way to make crafting recipes?

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

1 comment

0

u could make the slots in a table also?

1 answer

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

1 comment

0

Didn't work unfortunately. I'll give you an update if I somehow altered it to make it work

This discussion is preserved as it was. New answers, comments, and votes are closed.