Changing Enum.KeyCode by string Value

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

It’s because you’re using KeyCode as a string.

local function CtrlImput(input)
	if KeyCode == "RightControl" then -- We don't need to check if it's a string...
		
	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

Instead:

local function CtrlImput(input)
	if KeyCode == Enum.KeyCode.RightControl then
		
	else
		
	OpenKey = 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

This ain’t gonna work OpenKey property will be just = B or C and etc. but to make it work it must be = Enum.KeyCode.B

You tried the script or are you just saying?

I need to gtg rn, so i didn’t check it right now, i checked it before like same script, but am’ma check tommorow

That’s works i think, but now i have infinite UserInputService loop, it just do not stop

Make a debounce or a bool to check if it can Activate.