I have leg pain in both of my legs. They hurt when I lay down at night. I wonder if it could be from bad heart?

Restless leg syndrom. Do you have obstructive sleep apnea? Rls goes along w/ osa. See a sleep specialist, either a neurologist or pulmonary md.
Leg pain-. Your physician can help yo the best -but I would ask them to test you for sleep apnea as this happens to some people.