execute as @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{NoPickup:1b}}}}] at @s on origin run data modify entity @e[type=item,sort=nearest,limit=1] Owner set from entity @s UUID
execute as @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{NoPickup:1b}}}}] run data modify entity @s PickupDelay set value 0s
execute as @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{NoPickup:1b}}}}] at @s on origin run tp @e[type=item,sort=nearest,limit=1] @s

execute as @s at @s if block ~ ~-0.001 ~ minecraft:barrier run function koncept:return_stage with storage stage:checkpoint
execute as @s at @s if block ~ ~-0.001 ~ minecraft:yellow_stained_glass run function koncept:return_stage with storage stage:checkpoint
execute as @s at @s if block ~ ~-0.001 ~ minecraft:brown_stained_glass run function koncept:return_stage with storage stage:checkpoint

execute as @a if score @s[nbt={SelectedItem:{components:{"minecraft:custom_data":{return_stage:1b}}}}] carrot_on_a_stick matches 1.. at @s run function koncept:return_stage with storage stage:checkpoint
execute as @a if score @s[nbt={SelectedItem:{components:{"minecraft:custom_data":{return_spawn:1b}}}}] carrot_on_a_stick matches 1.. at @s run tellraw @s ["",{"text":"Are you sure you want to start the game again? ","color":"#ffcc64"},{"text":"[Yes]",click_event:{action:'run_command',command:"/trigger return_spawn"},"color":"green"}]

execute as @a if score @s[nbt={SelectedItem:{components:{"minecraft:custom_data":{return_spawn:1b}}}}] carrot_on_a_stick matches 1.. at @s run scoreboard players reset @s carrot_on_a_stick

scoreboard players reset @s carrot_on_a_stick

scoreboard players enable @s return_spawn

execute as @s[scores={return_spawn=1..}] at @s run function koncept:return_spawn

execute unless entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{NoPickup:1b}}}}] run execute as @a[nbt=!{Inventory:[{components:{"minecraft:custom_data":{return_stage:1b}}}]}] at @s run function koncept:count/1

execute unless entity @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{NoPickup:1b}}}}] run execute as @a[nbt=!{Inventory:[{components:{"minecraft:custom_data":{return_spawn:1b}}}]}] at @s run function koncept:count/2

execute as @s[nbt=!{Motion:[0.0d,-0.0784000015258789d,0.0d]},tag=count_return] at @s run function koncept:count/count_return_stage