I have a TextBox that needs to be a number.
How can I check if TextBox text type is only numbers? (maybe something like: if string.type(path) == "number"
function check(var) if tonumber(var) ~= "" and tonumber(var) ~= nil then return true end end check(23)
try this
Try this:
local textbox = script.Parent.TextBox textbox.Changed:Connect(function() local text = tonumber(textbox.Text) if text ~= nil then print(text) end end)
If the text has any letter added, the if-then statement will prevent whatever you're trying to do from being fired.
To not let them type non-digit characters, you can use the string pattern %D+
. It matches 1 or more occurrences of non digit characters.
With that in mind...
textbox.Text = textbox.Text:gsub("%D+", "")
will look for non digit characters and replace them with empty string ""
.
textbox:GetPropertyChangedSignal("Text"):Connect(function() textbox.Text = textbox.Text:gsub("%D+", "") end)