Variable not defined (AppleScript)
namedFolder only exists in the scope of your tell block. Define it first thing so that it will persist after you’re done with Finder.

set namedFolder to ""
tell application "Finder"
    ...
end tell
return namedFolder


Alternatively, you could just put the return statement inside the tell block.