How do I add mobs to a team and make them passive to me? [duplicate]

Ok, I want my character to either be ignored by zombies or unable to die (invincible). I've tried:

  • Adding a health scoreboard but this is uneditable

  • A repeating command block that gives the player instant health

    effect give @a[scores={ifBeast=1..}] minecraft:instant_health 1 10
    
  • Making the player invisible (If you get close to the zombies they chase you)

None of the above work. The option that I would prefer is for the Zombies to completely ignore the player, but if I must resort to them being invincible to zombies while still getting hit (irritating) then I will accept that.


Create a team:

1.13+: /team add friendly
1.12-: /scoreboard teams add friendly

Join the team:

1.13+: /team join friendly
1.12-: /scoreboard teams join friendly

On a clock, make all zombies join the team:

1.13+: /team join friendly @e[type=zombie]
1.10-: /scoreboard teams join friendly @e[type=Zombie]

Mobs in the same team as you will not attack you.