This doesn’t relate to any 2D feature. I’ll move your post to the Scripting forum.
Please note, you can post code using code-tags , you don’t need to paste screenshots which make it very hard for someone to refer to the code. They cannot copy/paste, refer to a line number etc.
Also note, you can edit your posts.