# I need help with this math thing (read to understand more)

Heyy, developers! I’m currently trying to add the numbers inside of a text label. for example (random number + or - random number). I’m not sure how to fix this.

``````		if player.PlayerGui.Math.ImageLabel.TextBox.Text == mathSplit[1] mathSplit[2] mathSplit[3] then -- 1 is a number, 2 is a - or +, 3 is a number
``````

So it looks like this?
`1 + 2`
and you want to split it into:
`{1, "+", 2}`
to then get:
`3`
and set text to that?

Try this:

``````local values = string.split("1 + 2", " ")

local operators = {
["+"] = function(a,b)
return a+b
end,
["-"] = function(a,b)
return a-b
end,
["*"] = function(a,b)
return a*b
end,
["/"] = function(a,b)
return a/b
end,
}

if #values == 3 then --there are enough values
if operators[values[2]] then --operator can be solved
if tonumber(values[1]) and tonumber(values[3]) then--LHS and RHS are numerical
print(operators[values[2]](values[1], values[3]))
else
end
else
end
else
end
``````

I’m getting my values from a table is the thing. I can message you the whole script, if you want

``````local result
if mathSplit[2] == "+" then
result = tonumber(mathSplit[1]) + tonumber(mathSplit[3])
elseif mathSplit[2] == "-" then
result = tonumber(mathSplit[1]) - tonumber(mathSplit[3])
end

if player.PlayerGui.Math.ImageLabel.TextBox.Text == tostring(result) then -- 1 is a number, 2 is a - or +, 3 is a number
``````

Needs to be like this.

This may error if `mathSplit[1]` or `mathSplit[3]` aren’t numbers though.

How would I make it so that the mathsplit[1] is greater then the mathsplit[2] during subtraction

Also, its saying that the answer I inputed is wron, since I noticed that the text in the textbox doesn’t come over to the script.

That means `TextBox.Text` is different from whatever `tostring(result)` returns.

You need to debug that on your end.

Tjis doesn’t work for some reason. Whenever I print that value, it becomes nil.

``````	local result
local input

player.PlayerGui.Math.ImageLabel.TextBox:GetPropertyChangedSignal("Text"):Connect(function()
input = player.PlayerGui.Math.ImageLabel.TextBox.Text
end)``````

Also, how would I make sure that when you subtract, the first number isn’t bigger than the second

`tonumber()` returns nil if its argument cannot be coerced into a number type value.

You need to debug this on your end by printing the values you’re working with.

You use the `>` or `<` comparison operators to determine if an operand is less than/greater than another operand.

You can modify the result of the operation using math.abs(n), assuming all the numbers are positive. If they arent, you can use math.max(n1, n2) - math.min(n1, n2)