So I’m not entirely sure what you’re doing, but I think I get a general idea of what you want. So the way I think of this is that I can create a split version of the block and then use a model to move the parts to the reference part’s pivot point. This means the code I’ve written is assuming that the reference part’s pivot point is at the center, which is the default.
local function splitPart(part: BasePart, sections: Vector3): Model
local splitModel = Instance.new("Model")
local totalSections = Vector3.new(
math.round(math.max(1, sections.X)),
math.round(math.max(1, sections.Y)),
math.round(math.max(1, sections.Z))
)
local sectionSize = part.Size / totalSections
for x = 1,totalSections.X do
for y = 1,totalSections.Y do
for z = 1,totalSections.Z do
local sectionPart = part:Clone()
sectionPart.Size = sectionSize
sectionPart.Parent = splitModel
sectionPart:PivotTo(CFrame.new(
Vector3.new(x, y, z) * sectionSize
))
end
end
end
splitModel:PivotTo(part:GetPivot())
return splitModel
end
local referencePart = workspace.Part
local splitPartModel = splitPart(referencePart, Vector3.new(5, 2, 2))
splitPartModel.Parent = workspace
referencePart:Destroy()
So what the splitPart function above is doing is that it’s getting the total amount of sections needed for each dimension of the split with math.max
to ensure it’s nothing below 1, and it removes any decimals with math.round
. Doing this ensures that the totalSections
variable is a Vector3 with the amount of sections needed for each dimension.
Then I need to get the size for each section and set it to sectionSize
, which is just the size of the part divided by the amount of sections. Since you can divide Vector3s, that’s what I did to get the right size for each section part.
The for loops next handle creating the necessary parts for each dimension. Each newly created part uses the sectionSize
variable for their size and uses the current x
, y
, z
values from the loops to determine where to position the part relative to the other parts.
However, doing it this way will make a part with the correct amount of sections, but it will be positioned in the wrong place. Here is what that’d look like:
And that’s why I use that last splitModel:PivotTo(part:GetPivot())
, so the splitPartModel will be positioned at the referencePart’s location.
This is more than most likely not the greatest way to do this, but it works for the most part, which is what matters to me (and probably to you). This should be a good starting point though.
If you wanted 16 sections only on the X axis, you could use splitPart(referencePart, Vector3.xAxis * 16)
.