Reading variables while the robot is moving for implementing a loop

Hello everyone,
I’m trying to read the z position and the force in the z direction of the robot to use them in a loop. I didn’t find anything about that online.
The objective is to push an object with a gripper downward until it reaches a certain height. The force should not exceed 30N. If the force is more than 30N the robot has to open the gripper, move upward, rotate the gripper at 90° and then try again.

I declared 2 variables, one is the third element of the list get_actual_tcp-pose and the other is the third element of the list get_tcp_force. Then I have a loop using the first variable with the condition : while variable 1>my final height. I move downward with another condition which is the force should not exceed -30N. The problem is, the variables are not changing while the robot is moving. And the loops never stops.

Can you help please ? Thank you in advance

For example:
https://www.universal-robots.com/articles/ur/programming/seek-using-force/
or
https://www.universal-robots.com/articles/ur/programming/urscript-dynamic-force-control/

There’s multiple ways to implement this. Can you show us a snippet of your code so we can better help you? Typically when I want to use the value of force() or of a specific TCP coordinate, I put a Thread at the bottom and just assign a variable like myForce = force(). That way the thread is constantly updating these values for use in my program elsewhere. If you go this route, just be sure to include a Script node and type “sync()” as the last instruction.

Thank you very much, both of you, I succeeded