Getting the thing holding a value

I wan to access the holder of the value for example

local book = {}
local book2 = book["book2"] = {}
local story = book2["Story"] =  "once a pon a time end"

how would I access book2 with the story variable?

What you are creating here is a multi-dimensional array. “book2” is a key for a table array, which holds the key “Story” and the value “once a pon a time end”
The data structure looks like this:

"book" : {
    "book2" : {
        "Story" : "once a pon a time end"

would return "once a pon a time end"

You need to access objects of “book2” in order to even get to the “Story” key in “book2”. Why do you need to access book2 using the story variable?

Im creating something and I do not have access to what would be book 2 in my case I have to get it

How are you accessing “Story” without accessing its parent, “book2”? Can you please share the code that you are working with?

I would rather not can you just tell me if it is possible or not? if so how

The only solution that is similar to what you are trying to do is “inverting” the table. Essentially, you will have to iterate over every element in the table.

local book = {}
local book2 = book["book2"] = {}
local story = book2["Story"] =  "once a pon a time end"

-- t is the table that you want to invert
function table_invert(t)
   local s={}
   for k,v in ipairs(t) do
   return s

-- Invert the book table.
local inverse_table = table_invert(book)

-- Now you can index this in reverse order.
book2 = inverse_table["Story"]

This method is not very efficient at all, as you have to loop through the ENTIRE table. This is also likely not helpful in your case, because if you have multiple keys with the value "Story", you won’t be able to directly get the “book” object that you are looking for.

Please try to find a more efficient way to do this. I am happy to help, if you would share the actual issue you are having in your code.

Do this:

local book = {}
local book2 = book["book2"]
if not book2 then
 book2 = {}
local story = book2["Story"]
if not story then
 story = "once a pon a time end"