So far this is what I have, but I want one where it just doesnt allow letters.
function CheckForNums(Box) if Box:IsA("TextBox") then TT = {} for i=1, #Box.Text do TT[#TT] = Box.Text end Box.Text = "" for _,v in pairs(TT) do if tonumber(v) ~= nil then Box.Text = Box.Text..v end end end end while wait() do CheckForNums(script.Parent) end
I'd like to know a better way as well~
local textBox = script.Parent:WaitForChild('TextBox') local function checkstr(str) local fullStr = "" for i in string.gmatch(str, "%d") do -- Only checks for numbers fullStr = fullStr..i end return fullStr end textBox.Changed:connect(function() local filter = checkstr(textBox.Text) textBox.Text = filter end)
Or as Disillusions pointed out
local textBox = script.Parent:WaitForChild('TextBox') textBox.Changed:connect(function(prop) if prop == "Text" then textBox.Text = string.gsub(textBox.Text,'%D+','') end end)