Issues with a datapack similar to "Double Life"
I'm trying to make a datapack that's basically my own version of Double Life from Grian's life series. I'm having a problem with it where if 2 players take different amouts of damage on (i assume) the same tick, they get caught in an infinite loop of setting their health to each other's. My code looks like this in the file that runs every tick.
Continue to help postscoreboard players add @a[scores={linked_life=0..2}] linked_life 1 execute as @a[scores={linked_life=2}] run function rebrand_life:linked_life/health/set_health_1t execute as @a store result score @s health run data get entity @s Health 100000000 execute as @a store result score @s max_health run data get entity @s attributes[{id: "minecraft:generic.max_health"}].base execute as @a at @s if score @s health > @s prev_health run function rebrand_life:linked_life/set_linked_health execute as @a at @s if score @s health < @s prev_health run function rebrand_life:linked_life/set_linked_health execute store result score @s prev_health run scoreboard players get @s health
If someone could give me tips on a way to move forward with this that would be great, thank you.