If you want the distance to be correct in any axis, not just their distance on the Z axis, use magnitude:
local distance = (sun.Position - eart.Position).magnitude
magnitude is a property of Vector3 that is the length of a line drawn from the Origin, (0,0,0) to wherever the Vector is (X,Y,Z). It is equivalent to math.sqrt(vec3.X^2 + vec3.Y^2 + vec3.Z^2), which is just the pythagorean theorem.
For a better explanation of my answer, Vector.Magnitude returns the distance of the Vector.
At the part.CFrame = CFrame.new... part, I’m placing the part at the earth’s position, looking at the sun’s position then pushing it towards it by half the distance.
I used -distance since -Z = front and +Z = back (Yes it’s inverted.)