How do you use Enum.KeyCode.Value, where value is a variable. Is it even possible to do something like that?

I’m trying to get to a point where I can if statement in a for loop that checks if a value from a table is being pressed. I’m having issues finding out how to check if that specific value being checked in the table is being pressed and is equal to true.

Line 32 is the issue
Code:
image

The error:

The enums are in lettersequence and Enum.KeyCode.lettersequence will error because lettersequence is obviously not a part of “KeyCode”. Instead, if you are trying to make sure both are down, you would want to do:

if UserInputService:IsKeyDown(v) then

You also don’t need the == true part because that would also be true. Basically, true == true would just be true

Remember, in the for loop, the i would be the index. For example: Enum.KeyCode.R would have index 1, and Enum.KeyCode.F would have index 2. V would be the enum itself.

You could change for i, v in pairs(lettersequence) do to for index, enum in pairs(lettersequence) do for better readibility.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.