How do I make the keycode the value of a NumberValue/StringValue with this:
local value = script.Parent.numValue.Value
if key.KeyCode == ??? then
//other code
end)```
How do I make the keycode the value of a NumberValue/StringValue with this:
local value = script.Parent.numValue.Value
if key.KeyCode == ??? then
//other code
end)```
Try this
local value = script.Parent.numValue.Value
if key.KeyCode == Enum.KeyCode.E then
//other code
end)
I know how to keybind, that works
Then can you elaborate the problem
I want to set the KeyCode
to a numbervalue
Can I ask wat are you trying to make?
Custom backpack UI. It all works except the keybinding
I believe tostring returns a string of the keycode.
For example, tostring(Enum.KeyCode.One) will return “One” (correct me if I’m wrong)
Besides that I’m not sure.
I want like the reverse of that tho
Oh ok I see. hmm I would use a table values. So like
local keybinds = {1 = Enum.KeyCode.One}
You could also just name your GUI elements “One”, “Two”, etc.
There’s not really a way to get 1 from Enum.KeyCode.One besides actually setting the values like Ashp suggested
local keys = {
1 = Enum.KeyCode.One,
2 = Enum.KeyCode.Two,
3 = Enum.KeyCode.Three,
4 = Enum.KeyCode.Four,
5 = Enum.KeyCode.Five,
6 = Enum.KeyCode.Six,
7 = Enum.KeyCode.Seven,
8 = Enum.KeyCode.Eight,
9 = Enum.KeyCode.Nine,
}
So i have this ^ and its saying, expected a name, got a complex expression
I think it’s supposed to be like this
local keys = {
[1] = Enum.KeyCode.One,
}
Or alternatively:
local keys = {
Enum.KeyCode.One,
Enum.KeyCode.Two,
}
Since they’ll be sorted numerically by default
Try this out. It seem plausible
You could try this:
local value = script.Parent.numValue.Value
if key.KeyCode = Enum.KeyCode[value] then
Tell me if I am wrong since I did not test this.
There is a different way you could achieve this. You could use KeyCode.Key.Value. Each key has an associated number to it that is built in. Why reinvent the wheel with a table when it already exists.
If you’re looking to return real numbers, the option is simple. Subtract 48 from any of the values and that will return a TRUE integer number representative of the Keycode. When you’re ready to convert it back, just add 48 to it, run string.char and then use Enum.KeyCode[whatever you string.char’d].
Dunno if that makes any sense.
I tried this and didn’t seem to work