So in my game I have these keybinds and I want the player to be able to change them, so far I have it so that they can only type in letters and they can’t type in numbers or spaces in the textbox.
The issue is that they can type in more than one letter, which will break the script.
This is some of the script:
local KeyBindBox = script.Parent.SettingsFrame.ScrollingFrame.ResetKeyBox
local ResetKeyBind = "R"
function onlyLetters(text)--This is the function that makes it so that they can only type letters
return text:gsub("[%A%s]+", "")
end
KeyBindBox:GetPropertyChangedSignal("Text"):Connect(function()
KeyBindBox.Text = onlyLetters(KeyBindBox.Text)
KeyBindBox.Text = string.upper(KeyBindBox.Text)
end)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode[ResetKeyBind] then
game.ReplicatedStorage.PlayerReset:FireServer()
end
end
end)
KeyBindBox.Focused:Connect(function()
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.Return then
ResetKeyBind = string.upper(KeyBindBox.Text)
end
end
end)
end)