counting nights slept by player

the idea is that I deactivated insomnia and I'm making it spawn when a given player sleeps for 3 nights (ideally in a row)

execute as @a[nbt={SleepTimer:100s}] run scoreboard players add @s DaysSlept 1 execute as @e[scores={DaysSlept=3..}] at @s run summon phantom ~ ~1 ~ execute as @e[scores={DaysSlept=3..}] run scoreboard players set @s DaysSlept 0

I've got all three set as repeating, with the third command block set to conditional. I couldn't figure out how to replicate this in a datapack, tried some thing which didn't work so wanted to get some direct help.

I also noted that if a player just keeps laying in bed for example a multiplayer, the first one just keeps running and it just spams out a bajillion phantom so was wondering if this issue is possibly fixable in datapacks?

Continue to help post