The error suggests that either $objectsInGroup1 or $objectsInGroup2 is an array, and not a single string. You cannot join an array (a list of items) to a single item, which is what it seems you are doing when you specify:
$objectsInGroup1 + ".rotateX"
Looking at your example code, it seems like you are trying to connect an attribute on multiple objects at once. This is impossible, you must iterate over the items in an array and set or connect the attribute individually on only one item at a time, something like this example:
for ($item in $objectGroup)
{
// do somthing to $item
}
In your example case, it seems you want to connect an attr from a single item in an array to another single item in another array 🤔
This is starting to become complicated by things like, what if there is a different number of items in one array than the other?
But, assuming both $objectsInGroup1 and $objectsInGroup2 are arrays with the same number of items, and you want to connect the 1st item in one with the 1st item in the other, then the 2nd in the first to the 2nd in the other, etc... you could do something like this:
int $count = `size $objectsInGroup1`;
for ($i=0; $i<$count; $i++)
{
connectAttr ($objectsInGroup1[$i]+".rotateX") ($objectsInGroup2[$i]+".rotateX");
connectAttr ($objectsInGroup1[$i]+".rotateY") ($objectsInGroup2[$i]+".rotateY");
connectAttr ($objectsInGroup1[$i]+".rotateZ") ($objectsInGroup2[$i]+".rotateZ");
}
I'm assuming though, that you are aware that $objectsInGroup1 and $objectsInGroup2 are arrays and what that involves...