So I'm making a Light Placing plugin (I know, super original!) and when i click, I want a gui to appear asking you things like "How bright?". But, obviously, is someone typed letters in it, it would obviously error.
M39a9am3R is right.
1 | --tonumber will turn a string into a number or return nil if the string is not a number |
2 | tonumber ( "hello!" ) --nil |
3 | tonumber ( "1244" )- 1244 |
Then to have the TextBox only use numbers, just do something like this.
1 | textbox = script.Parent.TextBox --or something |
2 | textbox.FocusLost:connect( function () |
3 | if tonumber (textbox.Text) then |
4 | --do stuff with textbox.Text being a number |
5 | end |
6 | end ) |
And if you wanted the players not be able to type letters, then do this.
01 | textbox = script.Parent.TextBox --or something |
02 | textbox.Changed:connect( function (prop) |
03 | if prop = = "Text" then |
04 | if not tonumber (textbox.Text) then |
05 | textbox.Text = textbox.Text:sub( 1 ,#textbox.Text- 1 ) |
06 | --using sub to delete the last thing in the string |
07 | --since this fires every single time they type something, it should delete letters instantly |
08 | end |
09 | end |
10 | end ) |