I edited my original reply with the updated code, apologies for any confusion. I incorporated all the points I mentioned including converting to degrees and changing the anchor point, as well as accounting for the fact AbsolutePosition is measured from the top left, not the centre of ObjectA and ObjectB.
Here's the code (copied from my edited reply):
local Plr = game.Players.LocalPlayer
local Gui = Plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
local ObjectA = Gui:WaitForChild("ObjectA")
local ObjectB = Gui:WaitForChild("ObjectB")
local Frame = Instance.new("Frame")
Frame.Parent = Gui
local positionA = ObjectA.AbsolutePosition + ObjectA.AbsoluteSize / 2
local positionB = ObjectB.AbsolutePosition + ObjectB.AbsoluteSize / 2
local avgPosition = ( positionA + positionB ) / 2
Frame.AnchorPoint = Vector2.new( 0.5, 0.5 )
Frame.Position = UDim2.new( 0, avgPosition.X, 0, avgPosition.Y )
Frame.Rotation = math.deg( math.atan2( positionB.Y - positionA.Y, positionB.X - positionA.X ) )
Frame.Size = UDim2.new(0, ( positionB - positionA ).Magnitude, 0, 4 )