Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help With Enum?

What is Enum? The only thing I use it for is UserInputService.

But never understood what it is? Can someone explain? What else can I use it for?? Thanks!

2 answers

✓ Accepted answer

Enum is short for enumeration and by definition means a list of all items in a collection.

Generally speaking, you can use Enum for almost everything!

You can find a whole entire list of what enums could be used for in Category:Enums. There are a total of 173 subcategories for enums in this link. (I wasn't kidding when I said they're used for almost everything.)

Example: Let's say I want to set a property for a part. I want to change the material of a part to diamond plate, for instance. I would do the following:

local part = Instance.new("Part")
part.Parent = workspace

part.Material = Enum.Material.DiamondPlate --Using enum to set a material property.

Enum has 173 or so subcategories as we have seen earlier. However, only a few of these categories are relevant to a Part. Some of these subcategories include:

  • Material
  • InputType

Note: There may be more; this is just an example.

Okay, we want to change Material. What can we choose from?

  • Plastic
  • Neon
  • WoodPlanks
  • Slate
  • CorrodedMetal
  • Foil
  • Grass
  • DiamondPlate
  • Fabric

Note: There may be more; this is just an example.

Alright, I want to choose DiamondPlate. So I write everything as follows:

part.Material = Enum.Material.DiamondPlate

1 comment

0

Wow! Now I understand! Thanks man!

Here this is how you use it:

local UIS = game:GetService('UserInputService')

UIS.InputBegan:Connect(function(input, gamestuff) -- when anything happens
    if gamestuff then  return end -- if dealing with gui stuff then stop
    if Input.KeyCode == Enum.KeyCode.W then -- change w to what u want
        -- code here
    end
end)

So, you would do:

Enum then Category (in this case KeyCode) and that thing you want.

the line you used should be: Input.KeyCode == Enum.KeyCode.F

or

Enum.KeyCode.F

I really don't know how to explain this sorry. This is just an example of how you can use it. You're basically trying to say if they input is f then.

Hope this helped in some sort of way.

Best of luck developer!

2 comments

0

Hey, thanks for answering. I might have phrased the question badly, could you read my question again? Thanks!

0

I dont need help with UIS but with -Enum- generally.

This discussion is preserved as it was. New answers, comments, and votes are closed.