new spawn system?

wanting to make a system where a player will spawn normally but the next time they die they will either spawn at their bed but if they dont have a bed they will spawn at new coords
Continue to help post