✓ Accepted answer
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.
1 comment
if string cant be converted to number then tonumber returns nil and you cant compare it with a number