String and Variable concatenation not working in Applescript

applescript

I'm trying to concatenate at variable within a path name string to make this script more efficient.
This is the code I have so far. But I can't seem to find the right syntax needed in order to set the variable in the string.

    set vserver to POSIX file "/Volumes/johndoe"
    set user to "johndoe" as string

    set source to POSIX file "/Users/johndoe/Documents"

    tell application "Finder"

        duplicate source to vserver with replacing
    end tell

I want johndoe to be replaces by variable user to make the code more maintainable for the future. My ultimate goal is to be able to copy multiple home folders including: movies, pictures, documents etc… onto a shared server.

I tried doing this

"/Users/" & user & "/Desktop"

But I received this error:

"Finder got an error: Handler can’t handle objects of this class."
number -10010

Best Answer

If you run

set user to "johndoe"
set source to POSIX file "/Users/" & user & "/Documents"

the result is

{file "Macintosh HD:Users:", "johndoe", "/Documents"}

Just put parentheses around the path:

set user to "johndoe"
set source to POSIX file ("/Users/" & user & "/Documents")