Restricting movement when entity is looked at (1.21.6)

(1.21.6) In a datapack, I have been trying to create a system where when a player with a certain tag (tag1) looks at another entity, they would be unable to move (which would likely be done through modifying movement_speed and jump_strength attributes), and then when they are not being looked at, they can move as normal. I am mainly having trouble with modifying the attributes of an entity that was looked at, and then resetting them to normal once they are not looked at. The current way that I am testing it is through this: execute as @a[tag=tag1] at @s anchored eyes facing entity @e[tag=!dead,tag=!tag1] feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..1.8] run execute at @a[tag=tag1] as @e[tag=!tag1,distance=..5] run effect give @s glowing 1 1 (my plan here was to replace it with a command that gives a tag, and another function constantly running that sets attributes to entities with that tag) execute as @a[tag=tag1] at @s anchored eyes facing entity @e[tag=!dead,tag=!tag1] feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=1.8..] run execute at @a[tag=tag1] run tellraw @a "line of sight disconnected" (my plan here was to replace it with removing of a tag, and running a function that resets the attributes back to normal to those without the tag) The main problem with this is that effects are given to all within the radius of the first command, not just the entity being looked at (although it is only activated when an entity is being looked at) The way I'm going about this could be totally wrong, and I'm fine rewriting it all for a better system, as long as it works.
Continue to help post