Answered by
XAXA 1569
9 years ago
ORIGINAL PROBLEM: given a variable "code" which stores a string, Enum.KeyCode.code will not work properly.
Given a dictionary d = { ["Pet"] = "Dog" }
, you can index Pet
to get the string "Dog"
in two ways:
d.Pet
, and
d["Pet"]
.
Likewise, you can "index" an Enum in two ways:
Enum.KeyCode.E
, and
Enum.KeyCode["E"]
.
Considering that code
is a string, you should index it the second way, like so:
1 | if inputObject.KeyCode = = Enum.KeyCode [ code ] then |
EDITED PROBLEM: When the user edits game.Players.LocalPlayer.codes.inventory
, the KeyCode does not change along with it.
The problem is that code
holds a string
, not the StringValue
. When the user edits the StringValue
, the string stored in code
does not change with it. To fix this, you should make code
hold the StringValue
instead (in this case, it's game.Players.LocalPlayer.codes.inventory
).
Line 1 should be:
1 | local code = game.Players.LocalPlayer.codes.inventory |
Since we made code
store the StringValue
itself instead of the string
, we have to fix line 6, like so:
1 | if inputObject.KeyCode = = Enum.KeyCode [ code.Value ] then |