Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What does "attempt to compare boolean with number" mean?

What does "attempt to compare boolean with number" mean?

Here is my script:

script.Parent.Touched:Connect(function(Part)
    if Part.Name == "B1" and 30 < script.Parent.Parent.Parent.Car.B1.Velocity.Magnitude < 90 then
      print("It is B1!")

On line two, it says that I am attempting to compare a boolean with a number. What does this mean and how can I fix it?

3 comments

1

you compare 30 < Magnitude which will reurn true / false then it compares < 90 you need to compare them indavidually ie 30 < Magnitude and Magnitude < 90.

0

do you not know english?

0

No I do little bud. I was quoting something. Maybe if you were smart enough to realize that.

2 answers

To solve this you need to separate the comparison, like this:

script.Parent.Touched:Connect(function(Part)
	if Part.Name == "B1" and 30 < script.Parent.Parent.Parent.Car.B1.Velocity.Magnitude and
script.Parent.Parent.Parent.Car.B1.Velocity.Magnitude < 90 then
      			print("It is B1!")
		end
	end
end)

As kingdom5 has mentioned, 30 < script.Parent.Parent.Parent.Car.B1.Velocity.Magnitude evaluates first then it will compare it to 90.

-- 30 < 40 is true
-- true < 90 errors

print(30 < 40)

-- Correct way
if 30 < 40 and 40 < 90 then
	print("This works")
end

if 30 < 40 < 90 then
	print("Doesn't work")
end

This discussion is preserved as it was. New answers, comments, and votes are closed.