You can do away with the isDeleted variable by using the command
object exist().
Below is your code turn into a function. Just call
CheckBallInBox(objnum) from in your main loop. This way you don't need any return values from your function but score will need to declared as a global variable or you will not see any change to it.
function CheckBallInBox(ball)
if object exist(ball)
cx = object screen x(ball)
cy = object screen y(ball)
if cx > ax and cx < bx and cy > ay and cy < by `if object is within box
delete object ball
Inc Score,1
endif
endif
endfunction
However this is better still:
function CheckBallInBox(objNum,x1,y1,x2,y2)
if object exist(objNum)
cx = object screen x(objNum)
cy = object screen y(objNum)
if cx > x1 and cx < x2 and cy > y1 and cy < y2 `if object is within box
delete object objNum
Inc Score,1
endif
endif
endfunction
Using this function you can check any object in any box.