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".
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.
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)
``
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]