Invalid argument #3 (string expected, got boolean)

  1. What do you want to achieve? trying to make a calculator that calclulates if like 1 < 3 is true or false.

  2. What is the issue? it keeps saying "invalid argument #3 (string expected, got boolean)
    Stack Begin and won’t work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? yes I looked everywhere nothing works.

				else
					if s.Text == "<" then
						a.Text = n1.Text < n2.Text
						print(a.Text)
					else
						if s.Text == ">" then
							a.Text = n1.Text > n2.Text
							print(a.Text)

image

n1.Text < n2.Text returns a boolean value. .Text is a string property. You will also want to tonumber the n1.Text and n2.Text because the comparison operators on strings will not compare them as you think.

You should be doing something along the lines of:

a.Text = tostring(tonumber(n1.Text) < tonumber(n2.Text))
3 Likes

use tonumber on the Text.

					if s.Text == "<" then
						a.Text = tonumber( n1.Text) < tonumber(n2.Text)
						print(a.Text)
					else
						if s.Text == ">" then
							a.Text = tonumber(n1.Text) > tonumber(n2.Text)
							print(a.Text)
1 Like

Ohh thanks that works, I should’ve thought of that