How to get the name of a variable?

I’m making a settings module and I need to know how I could get the name of the setting, but not the value of it.

How would I get this from a script? image

2 Likes
for name, value in pairs(Settings) do
    print(name, value)
    -- example: MusicSystem true
end
1 Like

You can just do Settings[“Name”] to get the value! :slight_smile:

1 Like

They just want to get the index I believe

1 Like

He wants the name, not the value

1 Like

Works when printing this, but in my script it seems to think the value is nil



function module:Boot(SettingsTable,GamepassTable,ProductsTable,CreditsTable)

	local SFolder = Instance.new("Folder",game:GetService("ReplicatedStorage"))
	SFolder.Name = "workFrameSettings"
	for _, name, value in ipairs(SettingsTable) do
		if typeof(value) == "string" then
			AddValue(name,"string",value)
		elseif typeof(value) == "boolean" then
			AddValue(name,"bool",value)
		elseif typeof(value) == "number" then
			AddValue(name,"number",value)
		else
			print(typeof(value).. " Error, other unknown value")
		end
	end
end

I want both, as I need the setting value. Would be a funny setting without a value lol

It’s just

for name, value in ipairs(SettingsTable) do

Worked thank you very much! :smile:

1 Like

It might be an issue with your implementation of ipairs, try replacing it with this temporarily to see if it changes anything:

function module:Boot(SettingsTable,GamepassTable,ProductsTable,CreditsTable)
	local SFolder = Instance.new("Folder")
	SFolder.Name = "workFrameSettings"
	SFolder.Parent = game:GetService("ReplicatedStorage")
	for name, value in ipairs(SettingsTable) do
		if typeof(value) == "string" then
			AddValue(name,"string",value)
		elseif typeof(value) == "boolean" then
			AddValue(name,"bool",value)
		elseif typeof(value) == "number" then
			AddValue(name,"number",value)
		else
			print(typeof(value).. " Error, other unknown value")
		end
	end
end

Side note: Don’t use the second argument of Instance.new

1 Like

Thanks for the heads up, I’ll keep that in mind and rewrite that part of my code.

1 Like