UnboundLocalError in line 384 & frozen participant screen

You have coder code which should be removed for use in Builder. For example, all Builder experiments automatically import a range of libraries.

# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import plugins
plugins.activatePlugins()
prefs.hardware['audioLib'] = 'ptb'
prefs.hardware['audioLatencyMode'] = '3'
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, hardware
from psychopy.tools import environmenttools
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER, priority)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os  # handy system and path functions
import sys  # to get file system encoding

import psychopy.iohub as io
from psychopy.hardware import keyboard

You shouldn’t therefore import visual, especially not 33 times (end routine within a loop of 3 repetitions of a spreadsheet with 11 conditions).

Also, PsychoPy will already be running in a window called win so when you execute win = visual.Window() you will break the current window. Are you trying to use two windows?

Here is a thread about how to do that