Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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?

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. User#5423 17 — 6y
0
do you not know english? cabbler 1942 — 6y
0
No I do little bud. I was quoting something. Maybe if you were smart enough to realize that. TheBeaver101 28 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
Ad
Log in to vote
0
Answered by 6 years ago

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

Answer this question