#set ID to 0, if enemy is stunned
execute if entity @s[scores={stun=1..}] run scoreboard players set .hit id 0 

#if enemy is not stunned - check for ID 1..
execute if entity @s[scores={stun=..0}] store result score .hit id run scoreboard players get @s id

#store the checked ID
execute store result storage minecraft:hit id int 1 run scoreboard players get @s id