Since you didn’t format your code correctly, we can’t see the structure. However, there are some errors that can be seen.
In your code you define three variables (potion, gold-key, and skeleton), all of which have previously undefined arguments. Arguments that are undefined should be expressed as strings, not variables. Once defined, they can be expressed as variables, but not until. The same is true for the event that triggers the onSpawn function.
From now on, please paste your code from the game using the </> button so we can see the structure and format. Help us help you. Thank you.
in the pet.findNearestByType(something), you need to use quotation marks, so it should be pet.findNearestByType(“potion”) not pet.findNearestByType(potion), and you should correct it in the other places