Hello, I’ve Tried Many Things To Fix The Problem I’ve Been Having Trying To Make A Custom Keybind Script. I Have It Working With Enum.KeyCode Pieces, But Not With The Symbols. I Don’t Know How I Might Do This Because Every Time I Try I Get An Error Saying It Gets A Nil Value, Even When It Shouldn’t Be A Nil Value. (Symbol As In The Shown Key On The Keyboard)
Script:
if self.PlayerData[Player.UserId][KeybindUsage] and (typeof(Enum.KeyCode:GetEnumItems()[string.char(KeybindChange.Name)]) == "EnumItem" and Enum.KeyCode[string.char(KeybindChange.Name)].EnumType == Enum.KeyCode) and not BlacklistedKeybinds[Enum.KeyCode[string.char(KeybindChange.Name)]] then
return true, string.char(Enum.KeyCode[KeybindChange]), Enum.KeyCode[string.char(KeybindChange.Name)]
Thank You In Advance For Any And All Answers To This To Help Me Understand Anything I Might Have Done Wrong. If You Need More Info, Ask Me Some Questions As Well. All The Items In The Script Are Defined Already. (Server Script)
I have tried using the values of the ‘KeybindChange’ but I’m trying to use a symbol such as ` so it doesn’t have a value so I’m trying to find a way to get the KeyCode that it correlates to.
You can get the value of a character by using string.byte on it
As for the getting a keycode part: I don’t know any built-in ways to look for a keycode using its associated character/value but you could use this:
Code
local function GetMatchingKeyCodeFromValue(Value: number)
for i, Keycode in Enum.KeyCode:GetEnumItems() do
if Keycode.Value == Value then
return Keycode
end
end
end
You’re definitely somehow using it wrong. The Roblox Keycode enums are tied to the ASCII table: https://www.asciitable.com/. If you don’t find the key you need then that sounds like a different problem.
You can make the original function I gave you check for the name of the key instead of its ASCII value:
local function GetMatchingKeyCodeFromName(Name: string): Enum.KeyCode?
for i, Keycode in Enum.KeyCode:GetEnumItems() do
if Keycode.Name == Name then
return Keycode
end
end
end