I have a function that chose's a random key from a table containing keys like : Q, E, R, T, Y, etc. Then i made this other function using UIS:
UIS.InputBegan:Connect(function(Input, gameProcessedEvent) local KeyCode = Input.KeyCode local keyPress = sgui:FindFirstChild("Menu").status.KPositioner.keyValue.Value if not gameProcessedEvent then if KeyCode == Enum.KeyCode.keyPress.Value then print("WEWE") end end end)
But when i wrote if KeyCode == Enum.KeyCode.keyPress.Value then
, it outputs an error. Since the keyPress's Value is a random key from the table, how would i make it so the KeyCode depends on the keyPress's Value?
You should know that there are two index operators (which is basically what you do with Enums).
The two operators are .
and []
.
Using the dot, it's always going to look with something with that name. Using the brackets, you can input a string or a variable to look for something inside.
To easily fix this you do
if KeyCode == Enum.KeyCode[keyPress] then print("WEWE") end