Welcome all!
today I will be showing you how to make number only textboxes!
For starters your going to need a script and a textbox!
I’m just going to put the script into the textbox!
Now lets begin!
For starters we need to make a variable for the textbox
local textbox = script.Parent -- change this to your textbox.
now we are going to need another variable, this one is going to be used to change the text back if the text is not a number.
local lastText = '' -- we set this to empty.
Now we need to be able to tell if the text is changed that way we can make sure it’s a number!
local textbox = script.Parent
local lastText = ''
textbox:GetPropertyChangedSignal('Text'):Connect(function() -- this funcion runs when you start typing
end)
now we need to check if the text is a number.
if you are wondering why we also check if textbox.Text == ‘’, this is so we can tell if its set to nothing. If we dont you will not be able to remove all the text from textbox while your typing.
local textbox = script.Parent
local lastText = ''
textbox:GetPropertyChangedSignal('Text'):Connect(function() -- this funcion runs when you start typing
if textbox.Text == '' or tonumber(textbox.Text) then -- we use "tonumber" to see if its a number
end
end)
Now we need to check if its not a number that way we can revert it back to its last text! And we also need to change the “lastText” variable to the text when it is a number or nil,
local textbox = script.Parent
local lastText = ''
textbox:GetPropertyChangedSignal('Text'):Connect(function() -- this funcion runs when you start typing
if textbox.Text == '' or tonumber(textbox.Text) then -- we use "tonumber" to see if its a number
lastText = textbox.Text -- set the text so we can revert it later
else -- this runs if its not a number or its equal to nil
textbox.Text = lastText -- we use this to change it back to its last text
print('Player is typing a letter')
end
end)
And that’s it! I tested this out and it works perfectly!
If you have any questions regarding this feel free to reply!
And that’s all folks. PEACE
video of it working: