How do I make it that /trigger will only execute a command once?

So I am making a datapack for custom enchantments. I want to make it where every time I use /trigger , then the command will be executed once. However, at the same time the objective value used in /trigger will be kept the same without continuously executing the /execute command in my tick.mcfunction. Is there a solution to this problem?


Create two scoreboards. One for the trigger and one normal one. In every tick you check if the value of both scoreboards are the same and run your function only if they are not:

# tick.mcfunction
execute as @a unless score @s name = @s name_trigger run function foo

# foo.mcfunction
tellraw @a [{"text":"My score is "},{"score":{"name":"*","objective":"name"}}]
scoreboard players operation @s name = @s name_trigger
scoreboard players enable @s name_trigger