Attempt to compare Boolean with number

I have a function to check closest vehicle for my vehicle shop but I am stuck at a error “attempt to compare Boolean with number” for some people.

When the model is loading, it throws that error.

My question is :

How can I check for if the value is Boolean? I have tried “if type(carDist) ~= “boolean” and bla bla bla” then" but it still gives the error. Any help would be appreciated.

Function :

Error line :

Error

I mean, it’s pretty self-explanatory - if carDist or carModel is not found (doesn’t exist, whatever), the check returns a false , which is indeed a bool. The way to avoid that, judging by the snippets you provided, would be to either add a separate condition to the if check (if carDist ~= false then) or to adjust the returned value (to, say, -1 so it will compare properly)
You can add a “standalone” check for the returned value being a bool, but that wouldn’t be the best decision for performance (although the impact is negligible both ways lol)

Try return 0 instead of return false in the function