I'd like to put some KeyCodes into a couple of ObjectValue fields, but the best it seems I can do is NumberValues, which don't correspond correctly to Enum.KeyCodes.
I know lua doesn't support bitwise operations or types, but I have my fingers crossed there's a fix for this.
It's always good practice to use Enums
Part.Material = Enum.Material.Glass Part.Shape = Enum.PartType.Ball
but it's also possible to use strings
, although not recommended (typos and other stuff that will make you cry)
Part.Material = "Glass" Part.Shape = "Ball"
but the least intuitive of them all are numbers, you can use numbers as well.
Part.Material = 1568 Part.Shape = 0
Why do numbers work? Isn't it odd that we can set properties that are enums, using numbers? It seems like we're pulling numbers out of thin air but actually, these numbers and enums are closely related.
Introducing EnumItem.Value
EnumItems
actually have a property called Value
which corresponds to that EnumItem's
Id. The same goes for KeyCode
, KeyCodes
have Values
as well.
So in order to put KeyCodes
into NumberValues
, what we can do is not store the KeyCode
but rather the Value
of the KeyCode
local NumberValue = Instance.new("NumberValue") NumberValue.Name = "KeyCode" NumberValue.Parent = script NumberValue.Changed:Connect(print) game:GetService("UserInputService").InputBegan:Connect(function(InputObject) if InputObject.KeyCode then NumberValue.Value = InputObject.KeyCode.Value end end)