AppleScript: Close all open Windows
The first issue is in what (application processes where visible is true) returns.

As an example, on a clean install of macOS 10.13 with just Finder and Script Editor open:

tell application "System Events" to get application processes where visible is true


Returns:

{application process "Script Editor" of application "System Events", application process "Finder" of application "System Events"}


What you really want is to get a list of names of applications that are visible, e.g.:

tell application "System Events" to get name of every application process where visible is true


Returns:

{"Script Editor", "Finder"}


The following example AppleScript code will try to close all open documents of each application and on error close all windows.

Now I opened some documents in TextEdit and Preview and some windows in Finder then ran the example AppleScript code. It closed all open documents in TextEdit and Preview and all windows in Finder, but not Script Editor.

Note: This will not close and Script Editor documents and silently errors out with:

error "The document can’t be closed while the script is running."




Example AppleScript code:

tell application "System Events"
    set theVisibleApps to (name of application processes where visible is true)
end tell

repeat with thisApp in theVisibleApps
    try
        tell application thisApp
            try
                close every document without saving
            on error
                close every window
            end try
        end tell
    end try
end repeat


Also note that with this example AppleScript code as coded will not close every document or close every window of an application that does not support those commands and should fail silently because of the try command.

This example AppleScript code is being presented to illustrate what's wrong with your present code and an example of how to help achieve your goal.