Maybe because the UI name is blank, so when you compare a blank string (uiname) to a blank string (%vehicle), the if statement returns true. I feel like you could of found this out by using echos though...
Edit: also in that if statement, you'd probably want to change %d.rideable $= true to:
%d.rideable
or
%d.rideable == 1
Edit #2: Ok so Uiname was either blank on some datablocks or it was correct, but had white spaces after it which is
what is causing your if statement check to fail ("Apples " is not the same as "Apples" for example).
This should work now, remember to use echos they can solve 90% of your problems.
function serverCMDcheckVehicle(%client,%vehicle)
{
echo("" @ %vehicle @ "");
%size = datablockGroup.getCount();
for(%i=0;%i<%size;%i++)
{
%d = getDataBlock(%i);
if(%d.rideable && (%d.className $= "FlyingVehicleData" || %d.className $= "WheeledVehicleData"))
{
%uiName = stripTrailingSpaces(%d.uiName);
if(%uiName !$= "" && %uiName $= %vehicle)
{
echo("TEST");
break;
}
}
}
}