Need help with textbox only accept between [? - ?] numbers

Does anyone know here to make a number that only accept numbers

Example: textbox only accept numbers between [1 - 6] but if player put the number 7 above, it will not accept it

local Numbers = {1,2,3,4,5,6}
local TextBox = -- TextBox Spot
for i,v in pairs(Numbers) do
if TextBox.Text == tostring(v) then
-- stuff
end

or you could also use

if table.find(tostring(Numbers),TextBox.Text) then
print("yes")
end

yo since its 1-6 then why not just check wether the chosen number is smaller then the biggest number and smaller then the smallest number (something like:)

if 6 >= Chosen >= 1 then
-- do something here
end

there is many ways to do it so yeah.

1 Like

First get the text box and detect for input, check the input Everytime something is typed, then if it’s over 6 then delete it.
Example:

local textBox = script.Parent

textBox:GetPropertyChangedSignal("ContentText"):Connect(function()
    local isNum, num = pcall(function()
        return tonumber(textBox.ContentText)
    end)
    if not isNum then return end
    if num < 1 or num > 6 then textBox.Text = "" end
end)
1 Like

for some reason it doesnt work [no errors]

oopsie i forgot to do tostring(v) cuz we need to convert the numbers to a string
or i could’ve just made the table like this local Numbers = {β€œ1”,β€œ2”,β€œ3”,β€œ4”,β€œ5”,β€œ6”} as strings.