Is there a way to get the Variable Name instead of its Value?

Hi Other Developers,

I’m trying to get the Variable Name out of a modulescript from a localscript but I’m getting the value not the name.

Here is the LocalScript:

for _, TableChild in pairs(QuestionsModule.EasyQuestions[SetNumber]) do
	if TableChild == UI.Name -- THIS PART HERE then
		UI.Text = Tab
		-- TODO
	end
end

Module Script is just a giant table and im looping through it
And I’m checking if the TableChild == the UI.Name but i want the TableChild Name not its Value

Help would be greatly appreciated!

1 Like

Do you mean the key? As in:

-- "Name" in this scenario?
["Name"] = "value";

If so, you can just use the index portion of the for loop (which you have as _):

for key, value in pairs(QuestionsModule.EasyQuestions[SetNumber]) do
    if key == UI.Name
        UI.Text = Tab
        -- TODO
    end
end
3 Likes