Help with number limit on a textbox

Hello! I have a textbox that lets you type in a number, but I don’t want the player to be able to type numbers above 6. This is the script I have so far, but I’m not sure why it doesn’t work. There are no errors in the output either.

local box = script.Parent

while tonumber(box.Text) > 6 do
	box.Text = "6"
	wait(.1)
end

The script is a localscript inside of the textbox by the way. Could anyone provide help? Thanks.

Try this:

local box = script.Parent

box:GetPropertyChangedSignal("ContentText"):Connect(function()
    if tonumber(box.ContentText) > 6 then
	    box.Text = "6"
    end
end)
2 Likes

Instead of using a while loop, you need to listen to the text change event.

local box = script.Parent

box:GetPropertyChangedSignal("Text"):Connect(function()
    if tonumber(box.Text) > 6 then
        ----the number is not okay
        box.Text = ""
    else
        ----the number is okay
    end
end)
1 Like

Thank you! When I get home I will certainly try that. I appreciate the help.

Got it. Will do when I get home. Thanks for your help!

Thank you both! Sadly I can’t mark both solutions, although I appreciate the help!

1 Like