How to use keys as strings without looping?

Here’s another way I guess you could do it.

local classes = {
	{"Flanker", {}} -- The table in the array would hold the attributes you want
}

-- To reference it do this
local function GetClass(class: string)
	for _, v in classes do
		if v[1] == class then
			return v -- or return whatever you want
		end
	end
end

local class = GetClass("Flanker")
print(class[1], class[2]) -- Output: Flanker {}

Also, another method to make it simple (all you need is tostring) is adding a metatable to the data.

for Name, Data in pairs(Classes) do
	setmetatable(Data, {__tostring = function() return Name end})
end
2 Likes

“pin” was just a test value for the moment

This could work, but I am trying to use Roblox’s Intellisense to help me program rather than needing it stored for use later in the game.

If you are setting metatables the intellisense should give you the prompts, but personally I have found this patchy for variables, only providing the prompt if I had used it before, but is better for methods.

The only real solution in this thread