How to find items in an array given the value?

I’m sorry I will probably explain this very poorly but I’m quite lost.

The way my system works:

  1. GUI show a list of options from an array from a script.
    Example:
local Recipes = {
	["Cookie Dough"] = {
		["Recipe"] = {
			"Bake Cookie"
		},
		["ImageId"] = 6219913164
	},
	["Cookie Dough & Chocolate Ice Cream"] = {
		["Recipe"] = {
			"Bake Cookie",
			"Scoop Ice Cream"
		},
		["ImageId"] = 6219909185
	}
  1. The player decides which one they want from the GUI.
  2. The GUI shows the recipe for the chosen item, from the script.
    This is how I’m currently doing that:
function Events.fetchData.OnServerInvoke(plr, ...) -- Event is fired as recipe = events.fetchData:InvokeServer("fetchItemRecipe",food)
	local Data = {...}
	local Request = Data[1]
	if Request == "fetchItemRecipe" then
		local food = Request[2] -- local food is the item from the array, e.g. Cookie Dough
		local recipe = Recipes[food]
		print(recipe)
		return recipe
	end
end

Although I am receiving nil as my response, any ideas or additional information needed?

Tables are indexed both by number and key. In this case your table is indexed by Key. So you can’t use a number to index it.

1 Like

So do I do Recipes[food]["Recipe"][1]?
I’m very confused

1 Like

Recipes[food]["Recipe"][1] is what I’ve tried and it gives me error attempt to index nil with 'Recipe'

Which means this part: Recipes[food]
is Nil. “food” value is not a string matching one of your keys.

1 Like

According to your script…

local Data = {...}

This actually equals

Data = {"fetchItemRecipe", food}
or
Data = { {"fetchItemRecipe", food} }

This part :
local food = Request[2]
Should porbably be:
local food = Data[2]