scoreboard players set @s inputCooldown 3

execute unless entity @e[limit=1,tag=player_char,type=area_effect_cloud] run tag @s add cannot_undo
execute if entity @e[scores={moveCommitTime=1..}] run tag @s add cannot_undo
execute if entity @e[limit=1,type=falling_block] run tag @s add cannot_undo
execute if score global availableResets matches ..0 run tag @s add cannot_undo
execute if score global levelLoading matches 1.. run tag @s add cannot_undo

execute if entity @s[tag=cannot_undo] if score global availableResets matches ..0 run tellraw @s ["",{"text":"Nothing left to undo!","color":"red"}]
execute if entity @s[tag=cannot_undo] unless score global availableResets matches ..0 run tellraw @s ["",{"text":"Can't undo while objects are moving!","color":"red"}]

execute if entity @s[tag=!cannot_undo] run function bd:game/perform_undo

execute if entity @s[tag=!cannot_undo] at @s run playsound minecraft:block.note_block.hat master @a ~ ~100000 ~ 100000
execute if entity @s[tag=cannot_undo] at @s run playsound minecraft:block.note_block.bass master @a ~ ~100000 ~ 100000 1.7

tag @s remove cannot_undo