It would also help a bit if you put your code into code tags so that it’s easier to read.
But, no, what has been posted here will not work for a repeater/sub field, only a top level field.
Are you trying to have a unique value in only the sub field for one post or all posts?