Getting brickcolor ID from name?

I am trying to make a script that will take the name of a brickcolor and return It’s corresponding ID.
ex: mid gray → 1002
List of brickcolors and ID’s: BrickColor | Roblox Creator Documentation

I didn’t find anything on the developer forums about converting brickcolor names to ID’s except this post, but the brickcolor ID’s didn’t seem to match up to the names.

How do I convert the brickcolor name to it’s ID? Did I miss anything from that post?

Hi! Yeah that was for getting colors from the palette. If you want an id from a name try this:

function getIdFromName(name)
	for i = 1, 1032 do
		if name == BrickColor.new(i).Name then
			return i
		end
	end
	return nil
end

This may not be the most efficient, but it’s what came to mind. I’ll edit with any other ideas I come up with.

You can also do BrickColor.new(name).Number maybe? I havent tested that

BrickColor.new("yourcolor").Number - see the BrickColor | Roblox Creator Documentation developer wiki

Bear in mind that BrickColor will return a “closest match” if you don’t select one of the BrickColors via name. For example, something like BrickColor.new(1, 1, 1).Number would return 1001 because it’s closest match is Institutional White.

Yeah, both of those methods work for what I’m doing. Thanks!