How to get the text of a key in a dictionary

Recently, I came across the need to use the name of a key rather than its value.
This is a slight example.

characters = {
   ["First_Character"] = {"Stuff"};
   ["Second_Character"] = {"Stuff"};
   ["Third_Character"] = {"Stuff"};
   ["Fourth_Character"] = {"Stuff"};
}

I have access to the all the keys (All the character keys), although I only want access to the key name. How can I access the keyname and not "Stuff".

So what is your question exactly?

I want to set the text of a button to the name of a key (first character, second character ect). Although when I access the keys, I get the {“Stuff”} Instead.

If you are doing characters["First_Character"], then it’ll return the data you have saved in that key.

How did you get “First_Character” originally, surely you can use that?

The only idea I had for this is to add [“Name”] = “name” under every key, but that would take ages and be unnecessary.

By typing it out, in a modulescript, do you want it sent?

Yes, please send all the code you were using.

It is too large for the text box, so.
Settings.txt (75.7 KB)

I just need the extract you are using to create the buttons & set their properties.

Oh, sorry, here it is

local settings = require(game.ServerStorage.Settings)

if game.ServerScriptService.Testers:FindFirstChild(game.Players.LocalPlayer.Name) then
	script.Parent.Visible = true
	local template = script.Parent.MenuFrame.Character_Menu.CharacterFrame.Template
	for i, v in pairs(settings["SansSettings"]) do
		local character = template:Clone()
		character.Parent = script.Parent.MenuFrame.Character_Menu.CharacterFrame
		character.Visible = true
		character.Text = "Would say V but that brings back a table"
	end
end


script.Parent.MenuFrame.Pick_Character.MouseButton1Down:Connect(function()
	script.Parent.MenuFrame.Visible = not(script.Parent.MenuFrame.Visible)
	
end)
``
Name = i
Description = type(v) == 'table' and v[1] or v
1 Like

The dictionary would have to be a ModuleScript(If you don’t have that already) and you must require a server script to that module script. And to print the key then you put this:
ServerScript

local module = require(--wherever you module script is)
local table = module.--name of dictionary table variable

print(table[--number of which line you want to print]