Hi Scott,
I am not sure if I fully understood your whole project (I am not sure if/why you need a slider) but if you want to just rename the layers that start with ‘Bar’ from bottom to top, this is a very simple script. You don’t need any slider/expressions to do something like this, but maybe I misunderstood something.
var comp = app.project.activeItem;
var str1 = 'Bar';
var numCounter = 1;
//making a regular expression that starts with str1
var regex = new RegExp("^" + str1);
//looping through all layers from last to first
for (var i = comp.numLayers; i >=1; i--){
var currentLayer = comp.layer(i);
var currentName = currentLayer.name;
if(currentName.match(regex)==str1){
//this layer name starts with str1
currentLayer.name = str1 + " " + numCounter;
numCounter++;
}
}