Help with making a shape split multiple times through a script

I am trying to recreate this


I cannot seem to make the range actually change shape. I have done all of the ray coding though.

I tried to use unions and stuff but I forgot that you can only use them on the server. I do not know how I would script this efficiently and to just make it work.