Get ( LastError ) only references the error code returned by the immediately preceding script step. (Better error handling is one of the items I requested very recently, see: http://forums.filemaker.com/posts/56b3613440 )
Since the preceding script step is Set Error Capture [on] and it does not generate an error, Get ( LastError ) is always returning a zero.
Get ( LastError ) also only returns error codes from script steps, not invalid data in a field.
So it would appear that you need to use a different expression than Get ( LastError ) in order to get the results that you need.
If you have a unique values validation set on the field where you are checking for unique values, you might try this code:
Commit Records [No dialog]
If [Get ( LastError) > 0 ]
Thanks for the solution and the explanation, Phil. That solved it.