Getting a tables variable along with values

In short I have this script that add certain effects to the player in this sort of example:

	["Oxygen Low"] = {
		0,
		0.1,
		500,
		30,
		{
			{"Shortness Of Breath", 1, 17, 100, 25, false},
			{"Respitory Arrest", 100, 100, 100, 350, false},
			{"Cardiac Arrest", 100, 100, 100, 370, false},
		},
		15,
		nil,
		{
			0
		},
		"Low Oxygen",
		Vector2.new(5,4),
		40,
		"Restless anxiety and headaches hint at low blood oxygen levels."
	},

Now I want to grab an item from a table along with its Variable name, as shown here:
image

Currently in this screenshot I am just printing out the entire table but I want to print out just one singular value. If I would to write print(Afflictions["Oxygen Low"]) it would print out only its contents:
image

How do I make the script print out not only its contents but also the variable name as shown in the first screenshot?

I’m not sure if I understood your question, but you can print the key followed by its value.

local key = "Oxygen Low"
print(key, Afflictions["Oxygen Low"])

maybe you could explain a little more

In the first screenshot I posted it prints out The variables name from the table, “=” and then the contents of it. I wanted to do this because the afflictions is just a long module of every possible affliction and I want to grab an affliction from that module and add it to a new table. Except each affliction can affect another affliction which is why I want to include this part so I can get the affliction names.

image

Sorry I don’t really know how to explain this lol

i’m still pretty confused (i also didn’t read the whole post)

print(Afflictions["Oxygen Low"][3])
--> 500

these “Variable names” are called indexes

I think what @lumizk posted is what you want.

local key = "Oxygen Low"
print("[",key,"] = ", Afflictions[key])

Sorry no I already said, this is not just for printing, I just was using print as an example. I’m just going to break it down:

Inside each affliction is a table containing all the other afflictions it will cause
image
^ these ones

Now to edit these afflictions all I do is search through the table doing Afflictions["Shortness Of Breath"] for example. Afflictions is the module that returns a table containing every single possible Affliction.

Now if I were to run the line of code it would return the contents of the found Affliction that being:

	{
		0,
		0,
		100,
		15,
		{
			{"Hyperventilation", 16, 16, 100, 5, false},
		},
		15,
		nil,
		{},
		"Shortness Of Breath",
		Vector2.new(6,0),
		nil,
		"Its hard to breathe. Possibly a sign of thin air, but the prognosis could be worse."
	},

Now what I WANT it to return is the exact same thing but at the start I want it to be [“Shortness Of Breath”] = …

Here is an Example again.

	["Shortness Of Breath"] = {
		0,
		0,
		100,
		15,
		{
			{"Hyperventilation", 16, 16, 100, 5, false},
		},
		15,
		nil,
		{},
		"Shortness Of Breath",
		Vector2.new(6,0),
		nil,
		"Its hard to breathe. Possibly a sign of thin air, but the prognosis could be worse."
	},