The reason you’re having trouble is that the problem is under-specified. You also have to specify the width of the part created for there to be a unique solution.
Then you can do this:
local part1, part2, p = script.Parent.White1, script.Parent.White2, Instance.new("Part", workspace)
local startPos = part1.CFrame:PointToWorldSpace(Vector3.new(part1.Size.X/2, 0, -part1.Size.Z/2))
local endPos = part2.CFrame:PointToWorldSpace(Vector3.new(-part2.Size.X/2, 0, part2.Size.Z/2))
-- First solve for the length using Pythagorean theorem
-- so we know the exact dimensions of the part we're working with.
local diagonal = (endPos - startPos).Magnitude
local width = 5
local length = math.sqrt(diagonal^2 - width^2)
local offsetThetaFromDiagonal = math.atan2(width / 2, length / 2)
local mid = startPos:Lerp(endPos, .5)
p.Anchored = true
p.CFrame =
CFrame.new(mid, endPos) *
CFrame.Angles(0, -offsetThetaFromDiagonal, 0)
p.Size = Vector3.new(width, .5, length)
Just had to make the offsetThetaFromDiagonal in the CFrame.Angles positive, and swap the negatives on the Z sizes in start and end Pos and I got exactly what I was looking for.
Assuming we had different numbers because of different part orientations.
In case someone in the future wants to see my end product for some reason
local part1, part2, p = script.Parent.White1, script.Parent.White2, Instance.new("Part", workspace)
local startPos = part1.CFrame:PointToWorldSpace(Vector3.new(part1.Size.X/2, 0, part1.Size.Z/2))
local endPos = part2.CFrame:PointToWorldSpace(Vector3.new(-part2.Size.X/2, 0, -part2.Size.Z/2))
local diagonal = (endPos - startPos).Magnitude
local width = 5
local length = math.sqrt(diagonal^2 - width^2)
local offsetThetaFromDiagonal = math.atan2(width / 2, length / 2)
local mid = startPos:Lerp(endPos, .5)
p.Anchored = true
p.CFrame =
CFrame.new(mid, endPos) *
CFrame.Angles(0, offsetThetaFromDiagonal, 0)
p.Size = Vector3.new(width, .5, length)