1 | if maxNum > 1000000000 then |
2 | return "Number too big" |
You're comparing maxNum
, a string, to 1000000000
, a number.
maxNum
is a string because you're firing over strings to the server:
1 | setNumberRangeFunction:InvokeServer(maxNumText.Text, minNumText.Text) |
What you should do is convert maxNum to a number whenever you're comparing it to a number:
1 | if tonumber (maxNum) > 1000000000 then |
2 | return "Number too big" |
There is another issue, where you're trying to compare if minNum
is bigger than maxNum
even though they are both strings:
And another instance where you compare if minNum
is lesser than maxNum
, even though they are both strings:
2 | local maxNumValue = script:WaitForChild( "MaxNumber" ) |
3 | local minNumValue = script:WaitForChild( "MinNumber" ) |
5 | maxNumValue.Value = tonumber (maxNum) |
6 | minNumValue.Value = tonumber (minNum) |
You should convert both variables to a number when comparing them like this.
What I suggest doing is setting minNum
and maxNum
to numbers at the start of the script. This way you don't have to call tonumber
every single time you want to compare them. (tonumber
will return nil if the string cannot be converted to a number, e.g. when the string is empty, so you can use that to check if the string is empty.) Here's what your code should look like:
01 | numberRangeFunction.OnServerInvoke = function (player, maxNum, minNum) |
03 | maxNum = tonumber (maxNum) |
04 | minNum = tonumber (minNum) |
06 | if maxNum = = nil or minNum = = nil then |
10 | if minNum > maxNum then |
14 | if minNum = = maxNum then |
18 | if maxNum > 1000000000 then |
19 | return "Number too big" |
22 | if maxNum ~ = nil and minNum ~ = nil then |
23 | if minNum < maxNum then |
24 | local maxNumValue = script:WaitForChild( "MaxNumber" ) |
25 | local minNumValue = script:WaitForChild( "MinNumber" ) |
27 | maxNumValue.Value = maxNum |
28 | minNumValue.Value = minNum |