3
I want to have a datapack that will run a command when you are stepping on a block, but only once; here is what I wrote:
execute as @a[scores={noreptest=0}] at @s if block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players set @s noreptest 1
execute as @a[scores={noreptest=1}] run say hi
execute as @a at @s unless block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players reset @a[scores={noreptest=1}] noreptest
This is not working, and noreptest never gets set to one. (The player does start with noreptest = 0, I made sure of this). However, when I change the code just slightly:
execute as @a at @s if block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players set @s noreptest 1
execute as @a[scores={noreptest=1}] run say hi
execute as @a at @s unless block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players reset @a[scores={noreptest=1}] noreptest
Then it works, but it runs the command every tick, not just once. Any help would be extremely appreciated thank you. This is my first time writing any datapack, and I know its simple but I want it to work.
execute as @a[scores={noreptest=0}] at @s if block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players set @s noreptest 1
execute as @a[scores={noreptest=1}] run say hi
execute as @a at @s unless block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players reset @a[scores={noreptest=1}] noreptest
This is not working, and noreptest never gets set to one. (The player does start with noreptest = 0, I made sure of this). However, when I change the code just slightly:
execute as @a at @s if block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players set @s noreptest 1
execute as @a[scores={noreptest=1}] run say hi
execute as @a at @s unless block ~ ~-1 ~ minecraft:ancient_debris run scoreboard players reset @a[scores={noreptest=1}] noreptest
Then it works, but it runs the command every tick, not just once. Any help would be extremely appreciated thank you. This is my first time writing any datapack, and I know its simple but I want it to work.
1
So, are you trying to run a command when a player steps on a specific block, but only do it once (every time the player steps somewhere else and again at the block)?
If so, here's how to do it:
You don't need to use scoreboards at all, tags are enough.
Just put this in the tick/loop function and modify it for your needs: (Keep the order!)
If so, here's how to do it:
You don't need to use scoreboards at all, tags are enough.
Just put this in the tick/loop function and modify it for your needs: (Keep the order!)
execute as @a[tag=!step] at @s if block ~ ~-1 ~ ancient_debris run say your commmandexecute as @a[tag=!step] at @s if block ~ ~-1 ~ ancient_debris run tag @s add stepexecute as @a[tag=step] at @s unless block ~ ~-1 ~ ancient_debris run tag @s remove step
