# Создаёшь скорборд
scoreboard objectives add deathCount deathCount
# В цикл
execute if entity @a[scores={deathCount=1},limit=1] run scoreboard players add .count deathCount 1
gamemode spectator @a[gamemode=survival,scores={deathCount=1}]
scoreboard players reset @a[scores={deathCount=1},limit=1] deathCount
#Если число смертей достигло 2, то выполняются следующие команды
execute if score .count deathCount matches 2 run gamemode creative @a[gamemode=survival]
execute if score .count deathCount matches 2 run scoreboard players reset .count deathCount