What does errAEWrongNumberArgs error mean running AppleScript?
With a script that long, you have two options to cure an error:


Use a debugger to step through the code and find out which of the 40 lines contains the error and inspect the value of the errors and the syntax for the command that’s being run or throws the error
Use the concept of minimum complete verifiable example - where you will remove the code logical part by logical part until you have the smallest amount of code that produces the errors. In this case, removing (or commenting out) all of the delays, all inner loops and have only a couple of lines of code to debug.


For debugger, the Apple tool is barely OK - so I would run and not walk to something like https://latenightsw.com/ Script Debugger which has a fully featured trial and then a free tier of functionality that will suit your needs perfectly.