Is not a valid member of "Enum.KeyCode"

I want to detect if the pressed key is equal to a value in the parent of the script.
The issue is it gives me the error : is not a valid member of “Enum.KeyCode”

I tried looking on the dev hub but i couldnt find anything that could fix it

local CD = false
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key,istyping)
	if istyping then
		return
	else
		if key.KeyCode == Enum.KeyCode[script.Parent.Key.Value] then
			if CD == false and game.Players.LocalPlayer.Stats.CursedEnergy.Value >= script.EnergyConsume.Value and game.Players.LocalPlayer.Character.Modifiers.Stunned.Value == false  then
				local Mouse = game.Players.LocalPlayer:GetMouse()
				CD = true
				local Name = script.Parent.Name
				game.ReplicatedStorage.CursedEnergy:FireServer(script.EnergyConsume.Value)
				game.ReplicatedStorage.BackpackDisable:FireServer()
				game.ReplicatedStorage.Techniques:FindFirstChild(script.Parent.Technique.Value):FindFirstChild(script.Parent.Name):FireServer(Mouse.Target)
				script.Parent.Name = script.CD.Value
				for i = 1,script.Parent.CD.Value-1 do
					script.Parent.Name -= 1
					task.wait(1)
				end
				CD = false
				script.Parent.Name = Name
			end 
		end
	end
end)
2 Likes

what is the current value of the key?

1 Like

The current value of the key is E.

try tostring(script.Parent.Key.Value)

1 Like

nope, didn’t work. here is the code i changed :

if key.KeyCode == tostring(script.Parent.Key.Value) then
1 Like

Enum.KeyCode[tostring(script.Parent:WaitForChild(“Key”).Value)]

1 Like

Which line does the error occur on? That should be displayed in the console.

1 Like

the error occurs on the line 8.

1 Like

Are you sure that value isnt “”?

nope, still gave me the error.

perhaps the value isn’t an uppercase letter

if not, make it an uppercase letter

You’re checking for the KeyCode Value, and a KeyCode can’t be a letter, it can only be a number.

I figured it out, after you said that I went to go check if it was or not. Then I remembered i set the key value in a server script, not a local one. Thanks!

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