How to replicate item B in the same groups and tags as item A

I’m running into an issue while trying to replicate item B in the same (tag) groups and tags as item A.

The following code snippet replicates B in every Group and Tag Group where A is replicated, but it duplicates it in the ordinary Tags of A. What’s wrong with it?

repeat with parentGroup in parents of A
	
	if id of parentGroup = id of existingParentGroup then
		-- do not replicate to initial parent
	else
		set theRep to replicate record B to parentGroup
	end if
	
end repeat

Could you please post the full script and screenshots before/after using the script? Thanks!

Nevermind, works like a charm now.