Group Color Changing

The “magic comment” for encoding must be the very first line in a file, or the second line if the first line is a “shebang”. (Ruby embedded script files do not use nor need “shebang” lines because they are not run outside of SketchUp.)

DO NOT add the "Untagged" layer-tag.
It is ALWAYS in the Sketchup::Layers collection.

Use simple reasoning. To find objects to affect with code, your code will search for theses objects.
To find the objects your code wants, give them a name. Then read this prior topic …

I will not comment further on your code as it uses $var global variables, which you have been told repeatedly not to use.

Use @var or @@var references inside your modules and classes.