I can't get the parts to align properly

I am trying to get this:
image

To this:
image

After hours on trying to find the solution, I decided the more talented minds the better, so I went to the DevForum.

The way this works is I have a bunch of parts that piece together like so:
image

I want to be able to make the pieces fit for every size and dimensions for the whole model, but I chose a square base for simplicity sake.

Here is my current code for positioning the parts:

--newwall is a one of the "pieces" shown of the image above
--corner is the corner of the floor below the model that is used to alignthe parts to the floor correctly
--walllengthx and walllengthz is the width of the newwall
--Parts running on z axis
newwall.Position = Vector3.new(corner.Z + ((i2)*walllengthz), corner.Y + modulesize.Y/2, corner.X + (i1) * walllengthx) + Vector3.new(newwall.Size.X/2, 0 , newwall.Size.Z/2) --move to corner
--i1 is the first for loop that decides which z axis it is out of 5
--i2 is the second for loop that decides which wall it is on that row selected by the first for loop
--Parts running on x axis
newwall.Position = Vector3.new(corner.X + ((i1)*walllengthz), corner.Y + modulesize.Y/2, corner.Z + ((i2)*walllengthz)) + Vector3.new(-newwall.Size.X/2, 0 , -newwall.Size.Z/2) --move to corner
--i1 is the first for loop that decides which x axis it is out of 5
--i2 is the second for loop that decides which wall it is on that row selected by the first for loop

I am not showing the entire script on purpose as my studio does not want any of the scripts to be public, feel free to ask for any information that you may require.

Thank you for taking your time to help!

So I figured out how to get the model to align with the floor (I started my for loop with 0 instead of 1), but I still haven’t solved the positioning part quite yet.