Is it possible to check if a player inputted a character like A or B in a text Box

Hi i am making a key bind selection and obviously i dont want the players inputting strings for their key binds and I made a text Box where they input and it checks if it is a character like A or B or C for example and then changes the module script accordingly .

local module = {
	
	InventoryButton = "E"
}

return module

I will add more keybinds for stuff eventually but i want to lay down the groundwork any ideas for me to check if it is a char that is being inputted

TextBoxes have an event “InputBegan.” The parameter it passes is the InputObject, where you can check if the key inputted is A B or C with InputObject.KeyCode

No i want them to make it any keybind but it has to be char and change the module

This doesn’t make sense. If you don’t want strings to be inputted, then don’t use a TextBox at all? TextBox’s Text property always holds a string.

If you meant that you only want a single character to be used, just compare the text length to 1:

if #text_box.Text == 1 then

Yes but that checks character length what im asking is there a data type called char because in other languages they have a char data type that can be checked accordingly im trying to check if it is a char and then the input length

I just made this to check if it is a valid key:

 local function IsValidKey(key)
    	key = tostring(key)
    	key = string.upper(key)
    	local result = nil
    	pcall(function()
    		result = Enum.KeyCode[key]
    	end)
    	return result
    end

    print(IsValidKey("E"))
    --> Enum.KeyCode.E
    print(IsValidKey("?re"))
    --> nil

When the user tries to change their keybind, you can check If it is valid with this function, else you set it back to what it was before or its default key.

You can then use something similar to this (I haven’t checked if it works properly, but you should definitely store the keys in a dictionary like this) when the user inputs a key in the textbox:

local Keys = {
	BackpackKey = Enum.KeyCode.E;
	SprintKey = Enum.KeyCode.LeftShift;
}

BackpackKeyTextbox.FocusLost:Connect(function()
	local validKey = IsValidKey(BackpackKeyTextbox.Text)
	BackpackKeyTextbox.Text = (validKey and BackpackKeyTextbox.Text) or DefaultBackpackKey
	
	Keys.BackpackKey = validKey or DefaultBackpackKey
end)

Oh so do i store the keys dictionary inside the local script and check if its default sorry im a little confused.

local PlayerKeyBindsModule = require(game.StarterPlayer.StarterPlayerScripts.PlayerKeybinds)
local InventoryKeyCodeLetter = PlayerKeyBindsModule.InventoryButton

local defaultInventoryBinds = {
	
	InventoryKeyCode = Enum.KeyCode[InventoryKeyCodeLetter]
}

Do you suggest i do this?

Have a module somewhere that has all the default keybinds. This is what you will originally use, for example:

local defaultKeys = require(modules.DefaultKeybinds)
local plrKeys = defaultKeys

BackpackKeyTextbox.FocusLost:Connect(function()
	local validKey = IsValidKey(BackpackKeyTextbox.Text) or defaultKeys.BackpackKey
	BackpackKeyTextbox.Text = string.sub(tostring(validKey),14,string.len(tostring(validKey)))
	plrKeys.BackpackKey = validKey
end)

How would you suggest i lay out the module because this is what i did so far using what you sent.

local PlayerKeyBindsModule = require(game.StarterPlayer.StarterPlayerScripts.PlayerKeybinds)
local InventoryKeyCodeLetter = PlayerKeyBindsModule.InventoryKey

local InventoryTextBox = script.Parent.PlayerInventoryBox

local defaultInventoryBind = {
	
	InventoryKeyCode = {
		InventoryLetter = InventoryKeyCodeLetter;
		InventoryDefaultBind = Enum.KeyCode[InventoryKeyCodeLetter];
	};
}


 
local function IsValidKey(key)   	
	key = tostring(key)   	
	key = string.upper(key)	
	local result = nil	
	pcall(function()   		
		result = Enum.KeyCode[key]   	
	end)	
	return result  
end

    print(IsValidKey("E"))
    --> Enum.KeyCode.E
    print(IsValidKey("?re"))


InventoryTextBox.FocusLost:Connect(function()
	local validKey = IsValidKey(InventoryTextBox.Text)
	InventoryTextBox.Text = (validKey and InventoryTextBox.Text) or defaultInventoryBind.InventoryKeyCode.InventoryLetter
	
	Keys.BackpackKey = validKey or DefaultBackpackKey
end)

And also i never used .FocusLost before and you used variables that i never used before. Like BackpackKey

Update it works but doesn’t get past the last line of code i think its a variable error @RVVZ