I have tried making a game, but for some reason my text box is not limiting the amount of letters, i have tried so much on the developer hub, and mainly i tried using this script:
local TextBox = script.Parent
TextBox.Changed:Connect(function()
TextBox.Text:sub(1, 2)
end)
The weird part is that for some reason, in my other games that worked perfectly all the time, but now on this specific game, it’s not working, can anyone help me? Any help would be appreciated.
Thank you.
– Heitorsonic123508 (no it’s not laheitorzito303030, this is my alt account)
This code should work for integers (whole numbers)
local TextBox = script.Parent
local Max = 12 -- Max value 12
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
local str = TextBox.Text:gsub("%D+", "") -- Only allows for numbers (0-9)
local number = tonumber(str)
if number then
TextBox.Text = math.min(number, Max)
else
TextBox.Text = ""
end
end)