Calculate angle between two parts using a middle part

So, I’m using a script given by @dthecoolest

local function generateRoof(depth,width,thickness,angleOfElevation,location, p)
    local roof1 = Instance.new("Part")
    roof1.Anchored = true
    roof1.Size = Vector3.new(width,thickness,depth)
    roof1.CFrame -= Vector3.new(width,thickness,0)/2 
    local pivotPoint = CFrame.new(0,0,0) -- Create decoy pivot that will "rotate"
    local offset = pivotPoint:toObjectSpace(roof1.CFrame) -- Get the offset from the part to the pivot
    local newPivot = pivotPoint*CFrame.Angles(0,0,math.rad(angleOfElevation))
    roof1.CFrame = newPivot*offset
    roof1.Position += location
    roof1.Parent = p

    local roof2 = Instance.new("Part")
    roof2.Anchored = true
    roof2.Size = Vector3.new(width,thickness,depth)
    roof2.CFrame += Vector3.new(width,-thickness,0)/2
    local pivotPoint = CFrame.new(0,0,0) -- Create decoy pivot that will "rotate"
    local offset = pivotPoint:toObjectSpace(roof2.CFrame) -- Get the offset from the part to the pivot
    local newPivot = pivotPoint*CFrame.Angles(0,0,math.rad(-angleOfElevation))
    roof2.CFrame = newPivot*offset
    roof2.Position += location
    roof2.Parent = p
end

And I edited some things to make it work with 2 nodes but it seems buggy, basically, it doesn’t have a static elevation, let me show what I mean

And my goal it’s achieve something like this


This is the currently script that calculates the width and depth

    local point1 = script.Parent.Point1.Position
    local point2 = script.Parent.Point2.Position

    local depth = math.abs(point2.X - point1.X)
    local width = math.abs(point2.Z - point1.Z)
    
    q:ClearAllChildren()
    
    generateRoof(
        width,
        depth / 2,
        0.5,
        15,
        point1:Lerp(point2, 0.5),
        q
    )

Just solved it, using this formula

local depth = math.abs(point2.X - point1.X)
local elevation = math.abs(point2.Y - point1.Y) -- Or just using a constant instead of difference.

local angle = (elevation * 100) / depth,

Edit: Unfortunately I found a bug as it doesn’t attach to the Y position.
Image from Gyazo