Code removed to save spaceYour meshcopying was too unpredictable - so I made some simplifications.
Now it only paints a brush and the meshes stay as they are.
Compare your code with this one - maybe it gives you some ideas how to make it uncomplcated and forseeable ;-) ?
And its 135 lines shorter
Since I don't know the rules what should happen on click (balls swap positions) - should a Ball be deleted? (was in your code on doubleclick) - now its jumping in 3 lines (what I suspect was planned?)...
EDIT What I didn't look into is what happens after pick. It was swapping meshes and should now be swapping array elements (color numbers 1 - 6) ... anyway it works without error