I am trying to make a keybind system that only allows specific letters to be entered into a textbox.
local UsableKeybinds = {"E","Q","F","V","1"}
How would I achieve this? I’ve looked already and it seems nothing could help.
I am trying to make a keybind system that only allows specific letters to be entered into a textbox.
local UsableKeybinds = {"E","Q","F","V","1"}
How would I achieve this? I’ve looked already and it seems nothing could help.
You check everytime the text in the textbox changes and loop through the text. If the character is not allowed just remove it
I found a better way
local textBox = script.Parent
local BadCharacters = "da"
textBox.Changed:Connect(function(property)
local t = textBox.Text
t = string.gsub(t, "["..BadCharacters.."]", "")
textBox.Text = t
end)
just add all the illegal characters to the BadCharacters variable
When the text changes :GetPropertyChangedSignal("Text") , loop through the text and if the character isn’t in the table table.find() change it using string.gsub
Don’t use textbox.Changed for this, you only want to check when the text changes.
This should work:
local UsableKeybinds = {"E","Q","F","V","1"}
local box = script.Parent
local function textChange()
if table.find(UsableKeybinds, string.sub(-1,-1)) == nil then
box.Text = string.gsub(box.Text, ".?$", "")
end
end