execute if score count_mobs darkmobs matches 0.. run data merge entity @s {Health:1024,Tags:["not_mob1"],active_effects:[{id:"minecraft:resistance",amplifier:1,duration:99999}],attributes:[{id:"minecraft:generic.max_health",base:1024}]}

scoreboard players add count_mobs darkmobs 1
execute if score count_mobs darkmobs matches 1.. run scoreboard players set count_mobs darkmobs 0