Hello! Firstly, let me point you towards the guide for using script tags . It helps make your code easier to read for people helping you.
The code you’ve provided isn’t very obvious as to how it works in the grand scheme of things. Could you explain a bit more about what objects this script is attached to? What is the targets
variable in this case?