I copied a bit more of the code. It appears to me that the if is under the else. My editor seems to be set to 5 space tabs and this code seems to be using 2 space tabs. I'm not sure if that is the problem. It looks ok to me in both places. Also copied the error msg from the dos window.
if state.customcursor == null:
Input.set_custom_mouse_cursor(null)
else:
state.customcursor = "res://files/buttons/kursor1.png"
if !state.mansionupgrades.has("farmmana"):
state.mansionupgrades.farmmana = 0
gameloaded = true
if str(state.currentversion) != str(gameversion):
print("Using old save, attempting repair")
repairsave()
SCRIPT ERROR: _on_end_pressed: Invalid get index 'farmmana' (on base: 'Dictionary').
At: res://files/scripts/Mansion.gd:1150