How can I generate folders named after column A in my spreadsheet and simultaneously duplicate a Google Docs document into those folders?

I have attempted to use various scripts from different YouTube creators that demonstrate how to achieve this, but I have not had any success. I would greatly appreciate any assistance with my issue.

function replicateDocumentAndCreateFolders() {
    const targetFolderId = "1XjR90tuQMap1R0KUO2KUp04tDLxOdV4o";
    const documentID = "1wBFVNEX88BgW2-98-w__SDmIxUT2wSlrmn7Vrd_pV4E";

    // Spreadsheet setup
    var spreadsheet = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1QA4WXvBiNGcGsXmONHo1bm9E7Y9WGDXIoWQ-UjqDz1c/edit#gid=0");
    var activeSheet = spreadsheet.getActiveSheet();
    var totalRows = activeSheet.getLastRow();

    // Drive setup
    var mainFolder = DriveApp.getFolderById("1QA4WXvBiNGcGsXmONHo1bm9E7Y9WGDXIoWQ-UjqDz1c");

    Logger.log(totalRows);
    for (var index = 1; index < totalRows; index++) {
        // Create a folder
        let customerName = activeSheet.getRange(index, 1).getValue();
        if (customerName !== "Customer") {
            var newFolderId = mainFolder.createFolder(customerName).getId();
            var newFolder = DriveApp.getFolderById(newFolderId);
            DriveApp.getFolderById(newFolderId).moveTo(targetFolderId);
            Logger.log('Folder Name: ' + customerName + ' Folder ID: ' + newFolderId);
            // Copying Document
            var destinationFolder = DriveApp.getFolderById(targetFolderId);
            DriveApp.getFileById(documentID).makeCopy(customerName, destinationFolder);
        }
    }
}

One possible solution is to tweak your script to avoid using the same mainFolder ID as your spreadsheet. It looks like there’s a confusion in declaring your main folder. Try ensuring that the mainFolder and the targetFolderId are different and point to distinct locations in your Google Drive. Also, when moving folders, use Folder.getFolderById().addFolder() to add the newly created folder to the target folder, instead of using moveTo(), which can potentially throw an error in some cases.