The enumeration data type, or Enum, is a fixed list of items. You can access enums through the global object called Enum. For a full list of Enums and their items, see Enums in the API Reference.

Getting Items of Enums

To get all items of an Enum, call the GetEnumItems() method on the enum. The following code sample demonstrates how to call GetEnumItems() on the PartType enum.

1local partTypes = Enum.PartType:GetEnumItems()
2for index, enumItem in ipairs(partTypes) do
3 print(enumItem)
7 Enum.PartType.Ball
8 Enum.PartType.Block
9 Enum.PartType.Cylinder

Enum Items

The EnumItem is the data type for items in enums. An EnumItem has three properties:

  • Name - The name of the EnumIem.
  • Value - The numerical index of the EnumItem.
  • EnumType - The parent Enum of the EnumItem.

Some properties of objects can only be items of certain enums. For example, the Shape property of a Part object is an item of the PartType Enum. The following code sample demonstrates how to print the properties of the PartType.Cylinder EnumItem.

1-- Properties of the EnumItem called Enum.PartType.Cylinder
2print(Enum.PartType.Cylinder.Name) -- Cylinder
3print(Enum.PartType.Cylinder.Value) -- 2
4print(Enum.PartType.Cylinder.EnumType) -- PartType

Assigning Enum Items

To assign an EnumItem as the value of a property, use the full Enum declaration. You can also use its Value or EnumType.

1local part = Instance.new("Part") -- Create a new part
2part.Parent = game.Workspace
4part.Shape = Enum.PartType.Cylinder -- By EnumItem (best practice)
5part.Shape = Enum.PartType.Cylinder.Value -- By EnumItem Value
6part.Shape = 2 -- By EnumItem Value
7part.Shape = Enum.PartType.Cylinder.Name -- By EnumItem Name
8part.Shape = "Cylinder" -- By EnumItem Name