If the target creature is an illegal target by the time Moment of Craving tries to resolve, it won't resolve and none of its effects will happen. You won't gain 2 life.
08-11-2024
wotc
The target creature will still be on the battlefield when you gain life, even if its toughness has been reduced to 0 or less. Any abilities it has that interact with gaining life do so as appropriate. If any abilities trigger on you gaining life, the creature will be put into its owner's graveyard after that ability triggers but before it resolves.
Random a card of Magic: The Gathering (MTG), but you can also roll the D20 dice, random a Planeswalker, have fun with the random rules and more.