How to make it so you can only type in numbers

How do make it so that you can only type in numbers with a text box and you also can’t use shift to like write something else.

Maybe use the .Changed function and then check if the property is the text, if it is then run a function which removes all numbers or illegal characters from your textbox

There is a already a topic similar to this, hope this helps! I have tested it and it works. How would I create a number only TextBox?

1 Like
local Last = ""

TextBox:GetPropertyChangedSingal("Text"):Connect(function()
    if not tonumber(TextBox.Text) then
        TextBox.Text = Last
    else
        Last = TextBox.Text
end)

how does it work? I dont understand it.

  • The variable named “Last” holds the last valid input (which can only contain numbers).

  • Every time the player types something in, the GetPropertyChangedSignal(“Text”) event fires, which runs the function.

  • The function checks if the current bit of text the player has put into the text box can be converted to a number.

  • If it can, it sets the Last variable to the bit of text.

  • If it can’t, then it reverts the text back to the last valid bit of text by setting it to whatever is the value of the Last variable.