Script that checks for apps with open window asks 'Where is Electron" in Electron apps
You need to use a different name for your repeat statement’s loop variable - the term name is an AppleScript property and is also in System Events scripting dictionary.  Your usage isn’t generating a syntax error, but it is probably causing more confusion than usual and is winding up targeting the wrong item (welcome to AppleScript).

You can use pipes around variable names like this where there may be a conflict (e.g. |name|), but CJK’s solution also avoids the repeat statement altogether.