hi this my first roblox devforum post again
my current code finds the distance from the cut indicator (the black part) to the top/bottom of the part and creates two new parts. it then moves the new parts accordingly and it deletes the original and the cut indicator
i need some help fixing my code to place the two new parts in the correct locations. my goal is for there to be no space between them. it should look exactly like the original part until it’s disturbed
it does this
local function Split(target, mouse, cut)
local top = target.CFrame * CFrame.new(0, target.Size.Y / 2, 0) * CFrame.Angles(math.pi / 2, 0, 0)
local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
local part0 = Instance.new("Part", target.Parent)
part0.Size = Vector3.new(target.Size.X, (top.Position - cut.Position).Magnitude, target.Size.Z)
part0.Color = target.Color
part0.Material = target.Material
part0.CFrame = target.CFrame + target.CFrame.UpVector * (top.Position - cut.Position).Magnitude
local part1 = Instance.new("Part", target.Parent)
part1.Size = Vector3.new(target.Size.X, (bottom.Position - cut.Position).Magnitude, target.Size.Z)
part1.Color = target.Color
part1.Material = target.Material
part1.CFrame = target.CFrame + target.CFrame.UpVector * -(bottom.Position - cut.Position).Magnitude
for i, v in pairs(target:GetChildren()) do
v:Destroy()
end
target:Destroy()
end
local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
local part0 = Instance.new("Part", target.Parent)
part0.Size = Vector3.new(target.Size.X, (top.Position - cut.Position).Magnitude, target.Size.Z)
part0.Color = target.Color
part0.Material = target.Material
part0.CFrame = CFrame.new(target.CFrame.p, cut.Position) * CFrame.new(0, part0.Size.Y / 2, 0)
local part1 = Instance.new("Part", target.Parent)
part1.Size = Vector3.new(target.Size.X, (bottom.Position - cut.Position).Magnitude, target.Size.Z)
part1.Color = target.Color
part1.Material = target.Material
part1.CFrame = CFrame.new(target.CFrame.p, cut.Position) * CFrame.new(0, -part1.Size.Y / 2, 0)
for i, v in pairs(target:GetChildren()) do
v:Destroy()
end
target:Destroy()
end
In this version, I’ve changed the calculation of the CFrame for part0 and part1. Instead of adding a vector to the target.CFrame, I’m creating a new CFrame positioned at the midpoint between the target.CFrame.p and cut.Position, and then offsetting it by half the size of the new part. This should ensure that the two new parts are exactly adjacent to each other.
I hope this helps with your Lumber Tycoon 2 project! Let me know if you have any other questions.
hello cool code
it made the parts spawn vertically, rather than assuming the orientation of the original part
it do this
kinda strange it does that but i’ll try messing around with your version some more to see if i can get it working right
thank you
hi your solution has been the closest to solving the problem so far
it eliminates the space between the parts but it moves them over a little still
ill mess with this some more to fix that part of it but thank you
local function Split(target, mouse, cut)
local top = target.CFrame * CFrame.new(0, target.Size.Y / 2, 0) * CFrame.Angles(math.pi / 2, 0, 0)
local bottom = target.CFrame * CFrame.new(0, target.Size.Y / -2, 0) * CFrame.Angles(math.pi / -2, 0, 0)
local part0 = Instance.new("Part", target.Parent)
part0.Size = Vector3.new(target.Size.X, (top.Position - cut.Position).Magnitude, target.Size.Z)
part0.Color = target.Color
part0.Material = target.Material
part0.CFrame = CFrame.new(cut.Position) * CFrame.new(0, part0.Size.Y / 2, 0)
local part1 = Instance.new("Part", target.Parent)
part1.Size = Vector3.new(target.Size.X, (bottom.Position - cut.Position).Magnitude, target.Size.Z)
part1.Color = target.Color
part1.Material = target.Material
part1.CFrame = CFrame.new(cut.Position) * CFrame.new(0, -part1.Size.Y / 2, 0)
for i, v in pairs(target:GetChildren()) do
v:Destroy()
end
target:Destroy()
end
In this new code, Its changed to CFrame.new(target.CFrame.p, cut.Position) to CFrame.new(cut.Position). This sets the CFrame of the new parts relative to the world axes, which should make them spawn in the correct orientation.
If you have any other questions, you know what to do.