Make the objective for the death scoreboard be tied to the player death objective. Then just have a repeating command block somewhere that's always loaded that sets people with a 1 in that objective to spectator. Then have a chain command block going after the repeating one that sets people with a score of 1 to have a score of 2 so that it doesn't target them multiple times.
So I have created death scoreboard and I want to check if someone is dead. If someone is dead then change his gamemode to spectator
Make the objective for the death scoreboard be tied to the player death objective. Then just have a repeating command block somewhere that's always loaded that sets people with a 1 in that objective to spectator. Then have a chain command block going after the repeating one that sets people with a score of 1 to have a score of 2 so that it doesn't target them multiple times.
Check out my mod! You can find it on CurseForge here:
https://www.curseforge.com/minecraft/mc-mods/the-spookjams-mod