You'll need to check if {{Scripter.Raw Interaction State}} is connected, if not then you put a 1-2 second delay and call the same script again.
That way it will loop until the correct state.
Depending on the use case triggers might be a better option.
https://help.mypurecloud.com/articles/about-triggers/
------------------------------
Jan Heinonen
Contact Center Specialist
GlobalConnect AB
------------------------------