Can anyone add to this Kirupa tutorial?

The tutorial here is great but does anyone know how to make this work but only when you’re mouse is within a certain distance of the that MC?