A lot of commands could be replaced with actual functions but seems okay enough to work. You need to do some debugging:
-
use world.sendMessage("a") function in various points of your code to make sure logic is flowing correctly. I usually do "a, b, c, d.. ect" (A debugger is better for this, look into it later as you get better)
-
Spawn a firework where the structure is loaded, sometimes the location inheritance is wrong. Usually running commands from dimension, but you are running from player so it should be fine? This is just debugging for loose cases.
-
Try simplifying your logic till you get it right. 1 just use the structure commands in game, then maybe from a script event, then the form. Break it into steps and find where it could have gone wrong.