Then, you were kinda close, but it should then be something like this:
if (getObjects(Slenderman.class).size()<6) { livescounter--; if (livescounter == 0) { Greenfoot.stop(); return; } else { addObject(new Slenderman(), getWidth()-1, Greenfoot.getRandomNumber(getHeight())); } }