Hi, I'm trying to make it so if you have all 4 ingredients, which I am calling Tea Tree Oil, Sandalwood Oil, Rose Oil and a Daisy, then you can make another oil called a Daisy Healing Oil. This code is inside an object I named the Mixing Bowl, and will only activate if you click on the bowl. And btw, the code on the top I don't think I really need but it references to the tools in ServerStorage. (I made it so when you click on the jars it puts it in your inventory) This is my code:
local ServerStorage = game:GetService("ServerStorage") local healing = ServerStorage:WaitForChild("Daisy Healing Oil") local tree = ServerStorage:WaitForChild("Tea Tree Oil") local sandal = ServerStorage:WaitForChild("Sandalwood Oil") local rose = ServerStorage:WaitForChild("Rose Oil") local daisy = ServerStorage:WaitForChild("Daisy") local clickDetector = script.Parent:WaitForChild("ClickDetector") function onClick(player) local inventory = player.Backpack for i, v in pairs(inventory:GetChildren()) do if v:IsA("Tool") and v.Name == "Tea Tree Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Sandalwood Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Rose Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Daisy" then v:Destroy() end end local clone = healing:Clone() clone.Parent = inventory print("Added to inventory!") end clickDetector.MouseClick:Connect(onClick)
Right now all it does is that if you have the 4 ingredients it removes them from your inventory and gives you the healing oil, but I want to make so you have to have all 4 ingredients or else it won't do anything, for example if you were making a recipe you can't make it if you don't have all the ingredients. Thanks.
Try this:
local ServerStorage = game:GetService("ServerStorage") local healing = ServerStorage:WaitForChild("Daisy Healing Oil") local tree = ServerStorage:WaitForChild("Tea Tree Oil") local sandal = ServerStorage:WaitForChild("Sandalwood Oil") local rose = ServerStorage:WaitForChild("Rose Oil") local daisy = ServerStorage:WaitForChild("Daisy") local clickDetector = script.Parent:WaitForChild("ClickDetector") local findtable = { "Tea Tree Oil", "Sandalwood Oil", "Rose Oil", "Daisy" } -- table of items ^ / function onClick(player) if player.Backpack:FindFirstChild(findtable[1]) and player.Backpack:FindFirstChild(findtable[2]) and player.Backpack:FindFirstChild(findtable[3]) and player.Backpack:FindFirstChild(findtable[4]) then local inventory = player.Backpack for i, v in pairs(inventory:GetChildren()) do if v:IsA("Tool") and v.Name == "Tea Tree Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Sandalwood Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Rose Oil" then v:Destroy() end if v:IsA("Tool") and v.Name == "Daisy" then v:Destroy() end end else print('not enough items') end local clone = healing:Clone() clone.Parent = inventory print("Added to inventory!") end clickDetector.MouseClick:Connect(onClick)