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:
01 | local ServerStorage = game:GetService( "ServerStorage" ) |
02 | local healing = ServerStorage:WaitForChild( "Daisy Healing Oil" ) |
03 | local tree = ServerStorage:WaitForChild( "Tea Tree Oil" ) |
04 | local sandal = ServerStorage:WaitForChild( "Sandalwood Oil" ) |
05 | local rose = ServerStorage:WaitForChild( "Rose Oil" ) |
06 | local daisy = ServerStorage:WaitForChild( "Daisy" ) |
07 | local clickDetector = script.Parent:WaitForChild( "ClickDetector" ) |
09 | function 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 |
15 | if v:IsA( "Tool" ) and v.Name = = "Sandalwood Oil" then |
18 | if v:IsA( "Tool" ) and v.Name = = "Rose Oil" then |
21 | if v:IsA( "Tool" ) and v.Name = = "Daisy" then |
25 | local clone = healing:Clone() |
26 | clone.Parent = inventory |
27 | print ( "Added to inventory!" ) |
30 | 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.