execute as @a[scores={checkpoint=40}] at @s run execute as @s[y=25,dy=0] at @s run function koncept:return_stage with storage stage:checkpoint

execute as @a[scores={checkpoint=40,checkpoint_between_40=0}] at @s positioned 31 36 -36 if entity @s[distance=..2] run tag @s add return_stage_checkpoint_message
execute as @a[scores={checkpoint=40,checkpoint_between_40=0}] at @s positioned 31 36 -36 if entity @s[distance=..2] run spawnpoint @s 31 35 -35 270.47
execute as @a[scores={checkpoint=40,checkpoint_between_40=0}] at @s positioned 31 36 -36 if entity @s[distance=..2] run scoreboard players set @s checkpoint_between_40 1

#40l4001 40l4002 40l4003 40l4004

execute positioned 32 29 -44 if entity @a[distance=..2] unless score 40l4001 timer_an matches 2 run scoreboard players set 40l4001 timer_an 1
execute if score 40l4001 timer_an matches 1 run scoreboard players add 40l4002 timer_an 1

execute if score 40l4002 timer_an matches 5 run function koncept:level/40/main_build

execute if score 40l4002 timer_an matches 45 run scoreboard players set 40l4001 timer_an 2

execute if score 40l4001 timer_an matches 2 run execute positioned 32 29 -44 unless entity @a[distance=..5] run scoreboard players set 40l4003 timer_an 1

execute if score 40l4003 timer_an matches 1.. run scoreboard players add 40l4004 timer_an 1

execute if score 40l4004 timer_an matches 30 run function koncept:level/40/main_destroy

execute if score 40l4004 timer_an matches 55 run scoreboard players reset 40l4001 timer_an
execute if score 40l4004 timer_an matches 55 run scoreboard players reset 40l4002 timer_an
execute if score 40l4004 timer_an matches 55 run scoreboard players reset 40l4003 timer_an
execute if score 40l4004 timer_an matches 55 run scoreboard players reset 40l4004 timer_an