

clear @s

execute as @a at @s positioned 102 35 6 if entity @s[distance=..3] run tag @s add start_player1
scoreboard players add @a[tag=start_player1] spawn 1
execute as @a[scores={spawn=1..}] at @s run function koncept:spawn1

execute if score spawn1 spawn matches 40 if score spawn spawn matches 1 run scoreboard players set spawn spawn 2

execute as @a at @s positioned 87 31 6 if entity @a[distance=..20,tag=!start_player] at @s run execute if score spawn spawn matches 0 run scoreboard players set spawn spawn 1
execute if score spawn spawn matches 1 run scoreboard players add spawn1 spawn 1

execute if score spawn1 spawn matches 40 if score spawn spawn matches 1 run execute as @a at @s positioned 87 31 6 if entity @s[distance=..20] at @s run tp @s ~ ~ ~ -90 0
execute if score spawn1 spawn matches 40 if score spawn spawn matches 1 run function koncept:spawn/main_build