Scripting Venture: Shelf w/ Randomized Boxes

In about a day’s worth of time, I managed to build a script that randomizes some properties of a group of parts to create an assortment of boxes on a shelf. I will explain everything the code does so far, so you understand the value of this in my script learning.

The boxes are first resized between a base and a maximum parameter, in this instance the Y direction, using a math.random function that I learned you can use multiples of 10 to achieve parameters smaller than whole numbers.
To compensate for the resize, as I couldn’t figure out how I could resize from a certain point or if that was possible, a function for correcting the position was added. Then, the resized part would truly be standing and not simply clipping through the surface its on.
Next, the code chooses between 6 colors (2 of which are duplicates of one another so as to homogenize the mixture a little bit) using another random function. I used BrickColors at first but then found out it would just be easier using Color3 RGB to port colors. The reason for which was because BrickColor simply didn’t like being chosen using the random function with the duplicate colors.
Finally, I added a function that shifts the boxes along its X or Z axis, depending on its initial rotation. It makes the model appear more lively and realistic in presentation and I’m very satisfied with how it turned out.


Boxes in base form. The smallest size is used.


Boxes randomized, but before the height correction after resizing was implemented.


After the height correction was implemented, the boxes now stand taller and feature more prominently.


Demonstration of the configurability of the script as of now. Note the dark brown and white colors might appear less frequently.

The end goal is to utilize this as a model for a building tool in my own Stamp Experimenting place. I would like to add some more visual features such as a strip of tape on the boxes (most likely to be accomplished using surfaceGUI, for its ability to automatically scale with parts). Overall, though, this is a great project for me and my lua learning.

(FYI this does use a custom PBR material. I absolutely love materials manager even in the beta.)

3 Likes