<p>I just completed my first print on my Ender-3 and when the print finalized itself the nozzle didn't elevate itself to clear away from the piece. I watched as the nozzle slowly lowered itself into my print and destroy it. Here is the gcode generated by Slic3r used:</p>

<pre>
; Filament-specific end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed
G91
G1 F1800 E-3
G90
G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif} ; Move print head up
G28 X0 ; home x and y axis
G1 Y180; Remove Print Position
M84 ; disable motors
M300 S2600 P100; Beep
; filament used = 24040.5mm (57.8cm3)
; total filament cost = 0.0
</pre>

<p><a href="https://i.stack.imgur.com/mZncw.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/mZncw.jpg" alt="preview of the destruction"></a></p>

Your print end code should have read something akin to this:
```
```
; Filament sy end gcode
G4 ; wait
M221 S100
M106 S0 ; turn off cooling fan
M104 S0 ; turn off extruder
M140 S0 ; turn off bed

; End code
G1 F1800 E-3 ; retract 3 mm
G1 Z30 ; Move print head up 30mm
G28 X0 ; home x and y axis
M84 ; disable motors
M300 S2600 P100; Beep
```
```
The problem with your end code is the
```
G90
```
for
absolute
measurements together with the formula
```
G1 Z{z_offset+min(layer_z+30, max_print_height)}{endif}
```
to set the height. The printer itself doesn't calculate anything. That what it doesn't interpret, it ignores, interpreting that whole thing as something crazy like
```
G1 Z30
```
to force the printer to go to Absolute 30 mm above absolute 0. To fix it,  your slicer would need to calculate
```
{z_offset+min(layer_z+30, max_print_height)}
```
for the printer - which seems to come out to 30mm above the print and then an if-statement that is not started anywhere.
Going up 30 mm can be much easier be done by staying in
```
G91 ; relative measurements
```
and calling
```
G1 Z30
```
to go up another 30 mm, though this might be too high for the printer frame.