Need help for scripting head movement

i’ve been trying to make r6 rig head looks at a target
so i found this solution which kind of solved my issue, but i want it to work in all axises
the problem is i have no idea for it to work
any help is appreciated

Do you mean something like this (my solution was not explicitly for IKControl)?