//svrCount will be used to see if all the servers are reporting in.
svrCount++;

// There is no reason why this shouldn't be StuckThreadCount.
// Checking anyway.
if (metric == "(.*)WorkManagerRuntime:StuckThreadCount")
{
//if the value is more than 0 then increment the svrSTCount.
if( value>0) {
svrSTCount++;
}
}
}

// Just to a spot check if six servers were found.
if (svrCount != 6){
log.info("The Prod Stuck Thread JS calcualtor found a different number of servers than were expected. 6 were expected, "+svrCount+" were found.");
}

// Return false if the script should not run on the MOM.
// Scripts that create metrics on agents other than the Custom Metric Agent
// should not run on the MOM because the agents exist only in the Collectors.
// Default is true.
function runOnMOM()
{
return true;
}

I have also tried using the addMetric with addMetric(metricName, count, value, min, max, metricType, frequency), and different types in metric but always got the same type of error.

That doesn't matter. Still get the error. Those two functions work fine, it is calling the addMetric function that fails.
By the way, I have a 9.5.0 environment that I tried it on and it failed there as well.