For a fruit to form on plants within this family the female flower must be pollinated with pollen from a male flower either by hand or by bees. If a male flower from another variety of plant is used the seeds within the fruit that forms will produce new hybrid varieties. Therefore in order to preserve the characteristics of the original heirloom variety ensure that the fruit you choose to save for seed has been pollinated (preferably by hand) from a male flower of the same variety (it may be from the same plant).
For seed to be viable the fruit must be fully matured. For zucchini this means growing far beyond the normal size it eaten until it becomes a large marrow and the skin starts to thicken. For pumpkins and squash the stalk starts to go brown when the fruit is fully mature. Cut the fruit and scoop out the seeds after which you may still eat the fruit. Wash the seeds removing all of the membrane and lay on cloth or paper towel on a plate or tray until they are fully dry and can be stored.
Seeds from this family will last 4-5 years when stored in cool and dry conditions out of direct sunlight.