Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make it so you can only do action if you have 4 ingredients? [Answered]

Asked by 4 years ago
Edited 4 years ago

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:

01local ServerStorage = game:GetService("ServerStorage")
02local healing = ServerStorage:WaitForChild("Daisy Healing Oil")
03local tree = ServerStorage:WaitForChild("Tea Tree Oil")
04local sandal = ServerStorage:WaitForChild("Sandalwood Oil")
05local rose = ServerStorage:WaitForChild("Rose Oil")
06local daisy = ServerStorage:WaitForChild("Daisy")
07local clickDetector = script.Parent:WaitForChild("ClickDetector")
08 
09function onClick(player)
10    local inventory = player.Backpack
11    for i, v in pairs(inventory:GetChildren()) do
12        if v:IsA("Tool") and v.Name == "Tea Tree Oil" then
13            v:Destroy()
14        end
15        if v:IsA("Tool") and v.Name == "Sandalwood Oil" then
View all 30 lines...

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.

0
make a variable local craftable = 0 in the first line of the function then instead of v:Destroy() type craftable = craftable + 1 then at the end if craftable == 4 then destroy the 4 ingredients and give the desired item AndreCool420 0 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

Try this:

  • it uses a table (findtable) and checks the items inside of the click
01local ServerStorage = game:GetService("ServerStorage")
02local healing = ServerStorage:WaitForChild("Daisy Healing Oil")
03local tree = ServerStorage:WaitForChild("Tea Tree Oil")
04local sandal = ServerStorage:WaitForChild("Sandalwood Oil")
05local rose = ServerStorage:WaitForChild("Rose Oil")
06local daisy = ServerStorage:WaitForChild("Daisy")
07local clickDetector = script.Parent:WaitForChild("ClickDetector")
08local findtable = {
09"Tea Tree Oil",
10"Sandalwood Oil",
11"Rose Oil",
12"Daisy"
13}
14-- table of items ^ /
15 
View all 41 lines...
1
It works, but I put lines 36-38 in-between lines 32-33, because before (with how it is above) it wouldn't give me the healing oil. Thanks G6plays 3 — 4y
0
No problem, glad you figured that out though! My bad. GoreDemons 215 — 4y
Ad

Answer this question