I'm trying to find a way to make it so when someone is outside during the day they get killed. I've searched for a long time and I've tried many different things, but they end up killing you even if you're safe.
It might seem like the best idea to use a daylight sensor for this, but that has lots of little problems, like being visible when placed at the player's location, potentially overwriting blocks (like grass), not being able to check its output level directly, …
Instead I would suggest simply checking for air in a column from the player's head to the build limit.
First make sure that you have a column of air at a known position, for example 0 0 (preferably in the spawn chunks):
/fill 0 0 0 0 255 0 air
Whenever you now want to check if everything above the player is air, you just need to compare with partially relative coordinates:
execute if blocks ~ ~ ~ ~ 255 ~ 0 ~ 0 all run <command>
The downside of this is that all blocks except air protect a player, including glass, buttons, signs, …
Well, the initial part is easy. You could hook up a daylight sensor with a command block, to trigger the command to deal damage by way of applying the "Instant_Damage" effect constantly, or kill them outright
/effect <player> minecraft:instant_damage /kill @p
Instant damage deals 3 damage each time it is applied, so it would require a clock setup.
However, I'm unaware of how you might need to go about checking for anyone who is "outside", beyond checking for players that are in an area that is of a certain light level, and you'd have to figure out what light level that is, as exposure to different light sources might throw this out a bit
I tihnk it would be best, if you would make a datapack for this. In a datapack you are able to have your own aliases, so you
are able to make one like 'not_protect', and then check if the area '~ ~2 ~ ~ 255 ~' contains something other than specified in your alias,
and then,at least, run your command.
Hope that this is what you've looked for.