First when comparing the mode variable to mode names, capitalization is significant. So all of those quoted strings need to have an initial capital letter, "Reset", "Record", etc.
For the double tap Mute, yeah, there is an interesting problem here.
The main body of the script (all the if..else if... code) will always run the first time you press the button. The OnRepeat function will only run on press 2, 3, etc. but the main part always runs. For scripts like this that swap between modes, those will always happen first before OnRepeat, in this case going from Play to Overdub, before the Mute happens.
There are ways to defer the moving from Play to Overdub, but that would mean that the Overdub would always happen after the timeout (default 1 second) rather than immediately which is probably not what you want. There is a tradeoff here, you can either make the script responsive to single taps, or you have to delay it for a 1/2 second or so to see if any other taps come in during that time.
Ignoring that problem for awhile, you can get the tap-2-Mute behavior like this:
function OnRepeat {
if repeatCount == 1 Mute
}
That gets you the double tap Mute, but you will see see all the single tap behavior happen first. I played around with deferring the Play->Overdub and it was harder than it should be because there are several states that have to be considered. I'll post that when I get it working, but I first wanted to make sure it was understood that you can't have "single tap but only if not double tap" behavior without deferring everything until after the double tap timeout.