function splitPart(part, fraction)
assert(fraction > 0 and fraction < 1)
local half1 = Instance.new("Part", workspace)
half1.Size = Vector3.new(part.Size.X * fraction, part.Size.Y, part.Size.Z)
half1.Anchored = true
half1.BrickColor = BrickColor.Random()
local half2 = Instance.new("Part", workspace)
half2.Size = Vector3.new(part.Size.X * (1 - fraction), part.Size.Y, part.Size.Z)
half2.Anchored = true
half2.BrickColor = BrickColor.Random()
half1.Position = part.Position + Vector3.new(half1.Size.X/2 - part.Size.X/2, 0, 0)
half2.Position = part.Position + Vector3.new(-half2.Size.X/2 + part.Size.X/2, 0, 0)
part:Destroy()
return half1, half2
end
local part = game.Workspace.Part
for _ = 1, 5 do
local p1, p2 = splitPart(part, math.random(25, 75)/100)
if math.random() > 0.5 then
part = p1
else
part = p2
end
end
The math for figuring out the sides is fairly simple. If the fraction is 1/10, the first half should be 10% of the size and the other should be “the rest”, i.e. (1 - 1/10) of the size, so 90%.
For the positions, if we wanted to center the first part on the left-most side of the original part, it’d be like so:
I tryed to make something, i dont know if it is what you wanted but here it is
function MakePart()
local Part = Instance.new("Part")
Part.Anchored = true
Part.CanCollide = true
Part.Parent = workspace
Part.BrickColor = BrickColor.Random()
return Part
end
function PartSplitter:Split(Part, x)
if not Part or not x then warn("Missing argument") return end
local Split1 = MakePart()
local Split2 = MakePart()
local SplitSize = Part.Size * Vector3.new(.5, 1, 1)
local Divide = 1 / x
local Rest = 1 - (1/x)
Split1.Size = Part.Size * Vector3.new(Divide, 1, 1)
Split2.Size = Part.Size * Vector3.new(Rest, 1, 1)
Split1.CFrame = Part.CFrame * CFrame.new(Part.Size.X/2 * Rest,0,0)
Split2.CFrame = Part.CFrame * CFrame.new(-Part.Size.X/2 * Divide,0,0)
return {Split1, Split2}
end
if x is 2 then the first side is 1/2 and the second side is the rest
if x is 3 then the first side is 1/3 and the other side is the rest
and so on you get the deal