Not sure if you need it to be in Hscript, but you could use a flow like this for inspiration
You can import it as well: