here' the script
script.Parent.BackGround2.Enter.MouseButton1Click:connect( function() local text = script.Parent.BackGround2.OrderNumberHandler.Text local number = tonumber(text) print("Number ", number) local OrdersHandler = script.Parent.BackGround3 if number >= 6 or not number then script.Parent.BackGround2.Enter.Text = "Number Not found" end end)
output when i put a letter:
08:59:09.714 - Players.raid6n.PlayerGui.ScreenGui.Main Script:6: attempt to compare number with nil
help?
I didn't test this but let's hope it works:
script.Parent.BackGround2.Enter.MouseButton1Click:connect( function() local text = script.Parent.BackGround2.OrderNumberHandler.Text local number = tonumber(text) if number ~= nil then print("Number ", number) local OrdersHandler = script.Parent.BackGround3 if number >= 6 or not number then script.Parent.BackGround2.Enter.Text = "Number Not found" end end end)
Why your script doesn't work:
script.Parent.BackGround2.Enter.MouseButton1Click:connect( function() local text = script.Parent.BackGround2.OrderNumberHandler.Text local number = tonumber(text) print("Number ", number) local OrdersHandler = script.Parent.BackGround3 if number >= 6 or not number then script.Parent.BackGround2.Enter.Text = "Number Not found" end end)
If a string can't be converted into a number, then tonumber()
returns nil
.
If you put something that isn't a number into text
then an error occurs at line 6, saying that it can't compare nil
to a number value. This is easily fixed by adding an if
statement to check if number
is equal to nil
.