An “Enumeration”, or “Enum”, is a special data type that can take one of a set of values. For example, the SurfaceType enum is used to select what type of surface a brick has on a certain side, which can take the values “Glue”, “Hinge”, “Inlet”, or a few more. These values act as constants in place of using ambiguous numbers or strings to set a value. You can use the Object Browser in Studio to see a list of all of the enums.
Enums have a single method:
|GetEnumItems()||Acts exactly like the GetChildren method and returns a table of all the EnumItems.|
The Enum object has a single method:
|GetEnums()||Returns a table of all the Enums.|
Enums are accessed through a global object called “Enum”. To get a specific enum, you must index this object. To get one of the EnumItems in a specific enum, you just index that enum.
You can set an enumerated property in a Roblox object through Lua in three different ways. It is preferred to set it with the enum object, however.
To set the RightSurface property in the
BasePart class to
game.Workspace.Part.RightSurface = Enum.SurfaceType.Weld game.Workspace.Part.RightSurface = 2 -- setting it with the id of the enum value game.Workspace.Part.RightSurface = "Weld" --Setting it with the name of the enum value
The EnumItem object acts as a constant of a specific enum. All members of any enum object are EnumItems.
The EnumItem object has three properties:
|Name||The name of the EnumItem object||"Read-Only"|
|Value||The id of the EnumItem for a specific Enum||"Read-Only"|
|Enum EnumType||The parent Enum that the EnumItem is within||"Read-Only"|