Changing Enum.KeyCode by string Value

Wait you mean Enum.KeyCode.KeyCode.Name?

Exactly, im pretty sure this returns the name of the enum value as a string.

But i do not need an return of enum value. I need to change it with string value

Yeah, like where you see me put in KeyPressed = input.KeyCode, it would be KeyPressed = input.KeyCode.Name. Also just gonna say, I didn’t even know it existed till now

Ok that’s better but i need to use this in Enum.KeyCode

image

local function ChangeKeyBind()

	KeyBindButton.MouseButton1Click:Connect(function()

		KeyBindButton.Text = "Waiting for Input..."
		UserInputService.InputBegan:Connect(function(input)
			local KeyPressed = input.KeyCode.Name
			KeyCode = KeyPressed
			KeyBindButton.TextScaled = "Change KeyBind... Current Keybind: "..KeyCode
		end)
	end)
end

Try to mess around with this code.

Literally same right now, alr did that myself, But i need to set OpenKey to This Keybind bcz i get OpenKey value when trying to open that thing

Alright wait, how does this do for you? Maybe we didn’t have to make the keypressed a string, but the end part where you send a print needs to just have the name

UserInputService = game:GetService("UserInputService")
KeyBindButton = script.Parent.ScreenGui.TextButton

local KeyCode

local function ChangeKeyBind()
	KeyBindButton.MouseButton1Click:Connect(function()
		KeyBindButton.Text = "Waiting for Input..."
		UserInputService.InputBegan:Connect(function(input)
			local KeyPressed = input.KeyCode
			
			KeyCode = KeyPressed
			KeyBindButton.TextScaled = "Change KeyBind... Current Keybind: "..KeyCode.Name
		end)
	end)
end

Same tho no working just checked

local function CtrlImput(input)
	if KeyCode == "RightControl" then
		
	else
		
	OpenKey = Enum.KeyCode..KeyCode
	end
	if input.KeyCode == OpenKey then
		if CtrlDebounce == false then
			gui.Visible = true
			CtrlDebounce = true
		else
			gui.Visible = false
			CtrlDebounce = false
		end
	end
end

here i’m changing OpenKey value

You probably don’t need an if statement for KeyCode == OpenKey.

Also why does OpenKey have two periods?

OpenKey = Enum.KeyCode..KeyCode

Bcz if use one period i still getting an error

Nah i need it means what KeyCode entered by player is same with OpenKey

1 Like

What does the error say when you do?

image

local Keys = {
	OpenGui = Enum.KeyCode.LeftControl
}

local CtrlDebounce = false
local UserInputService = game:GetService("UserInputService")

local function CtrlImput(input)
	if input.KeyCode == Keys.OpenGui then
		if CtrlDebounce == false then
			CtrlDebounce = true
			print("Is shift")
			Keys.OpenGui = Enum.KeyCode.LeftShift
		else
			print("Is ctrl")
			CtrlDebounce = false
			Keys.OpenGui = Enum.KeyCode.LeftControl
		end
	end
end

UserInputService.InputBegan:Connect(CtrlImput)

I hope this example helps

Just do OpenKey = Enum.KeyCode.Name

If that doesnt help I’m having a braintoot.

Even not what i need, table is interesting idea, but i still can’t change enum.KeyCode in table or somewhere else

image