Adding distance in the data command makes the command fail

I'm trying to making the command block detect the dragon phase within 100 blocks using this command:

execute store result score @a Dragon run data get entity @e[type=minecraft:ender_dragon,limit=1,sort=nearest,distance=1..100] DragonPhase

For some reason, it doesn't work because of distance=..100 and it works when I remove it. Any ideas what is causing this issue?


Solution 1:

Found my issue because the function didn't know the location to execute so I added execute at <target> and that fixes the issue.