Cooking System Support

Hi, I have been given a new task that I haven’t done before. It’s quite a new challenge and I am not quite sure how to approach this. I have looked more into tables and possible solutions regarding this, but still have no idea how to approach. I am trying to make a cooking system that will detect selected ingredients and then if they match up to a food, the food name will show up on the side.
I have been using tables to know which ones are selected. The way it finds the ingredients/foods, is through values. As seen below. Would anyone happen to know a possible way I could approach this?

Current Script
local Selected = {}

script.Parent.ScrollingFrame.ChildAdded:Connect(function(Ingredient)
	
	Ingredient.MouseButton1Click:Connect(function()
		
		if Ingredient.BackgroundColor3 == Color3.fromRGB(0,255,0) then
			
			local pos = table.find(Selected, Ingredient.Name)
			table.remove(Selected,pos)
			Ingredient.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
			
		else
			
			table.insert(Selected, Ingredient.Name)
			Ingredient.BackgroundColor3 = Color3.fromRGB(0,255,0)
			
		end
		
	end)
	
end)


for _,Food in pairs(game.ReplicatedStorage.Kitchen.Cooking.Ingredients:GetChildren()) do
	
	for _,Ingredient in pairs(Food:GetChildren()) do
		
		local Btn = script.Parent.ScrollingFrame.Template:Clone()
		Btn.Text = Ingredient.Name
		Btn.Name = Ingredient.Name
		Btn.Wait.Value = Food.Value
		Btn.Parent = script.Parent.ScrollingFrame
		
	end
	
end


-- And then, I am not quite sure how to approach detecting the foods for the ingredients selected.

How I organize the ingredients and foods;

Any help is appreciated. I hope I can learn from this.

I don’t quite understand what you mean by that. I’ve looked into that and still not sure how I would go about it. Could you explain more in-depth?

Hi, I asked for an explanation as I said I wasn’t quite sure what exactly the script does. I understand that it checks an area for ingredients. Would this area be the Food with the ingredients inside that food as shown in the post picture, or would it simply be a folder with all ingredients?

My script may not be scaleable with many Recipes.
But to maybe help you further. How exactly does your system work, and how are each of the Variables updated? Does each player have their own Variables?

You can just have this:
A function that will read through the required ingredients for the food, you’ll use this function to check the player’s food and match them.

Another function handles having food put on the cooking top of course. Within this, you’ll have it match and keep matching to other certain ingredients til it finds one that matches exactly/has the same food.

Another function to handle cooking/etc and giving the food.

Handling the functions

The first function I explained can be done by doing a for loop on all foods, within that there is another forloop that checks for the objects/ingredients inside. Then have it finally return those elements to another script/function.

The second script gets the returned values and keeps matching towards what the player is cooking to match it up.

Finally, last function handles giving the food as per usual.

There is no need for unneccessary long scripts, please don’t do that @Wizard101fire90, matching names/objects works fine instead.

If I were you I’d scrap the values, and make these into a module. This module would act as a Library, containing all the possible recipes. You could then check once the player has a certain amount of ingredients on a plate to check if he has accomplished the certain recipe, or just check every time the player lays down an ingredient.

1 Like

Greetings. I see you have had time to familiarize yourself with this task. If you could come onto my development team that would be great. Your skills are very much needed.

2 Likes