If you take 40 damage, but have resistance, you take 20 damage instead.
If you take 20 damage, but have resistance, you take 10 damage instead.
If you roll a saving throw that will change 40 damage to 20 damage, the above statements remain true - so you would take 20 damage on a failed save, or 10 damage on a successful save.