Serial monitor doesnt print

hi everyone, i am trying to get the ip from my code but it doesnt come in the serial monitor. here is my code

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <U8g2lib.h>
#include <BH1750.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 178, 177);
EthernetServer server(80);

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
BH1750 lightMeter;
//192.168.178.177
const int distancePin = A0, distanceDigitalPin = 7, magnetPin = 5;

void setup() {
  SPI.begin();
  server.begin();
  Serial.begin(9600);
  Wire.begin();
  lightMeter.begin();
  pinMode(magnetPin, INPUT_PULLUP);
  pinMode(distanceDigitalPin, INPUT);
  u8g2.begin();
  Ethernet.begin(mac, ip);
  Serial.print(Ethernet.localIP());

};

int getDistance() {
  return analogRead(distancePin) * 0.488;
}

void loop() {
      Serial.print(Ethernet.localIP());
  EthernetClient client = server.available();
  if (client) {
    client.readStringUntil('\r');
    client.flush();
    
    int lux = lightMeter.readLightLevel(), distance = getDistance();
    bool objectDetected = !digitalRead(distanceDigitalPin), magnet = !digitalRead(magnetPin);
    
    u8g2.clearBuffer();
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.setCursor(0, 10);
    u8g2.print(F("Licht: ")); u8g2.print(lux); u8g2.print(F(" lx"));
    u8g2.setCursor(0, 20);
    u8g2.print(F("Afstand: ")); u8g2.print(distance); u8g2.print(F(" cm"));
    u8g2.setCursor(0, 30);
    u8g2.print(F("Object: ")); u8g2.print(objectDetected ? F("Ja") : F("Nee"));
    u8g2.setCursor(0, 40);
    u8g2.print(F("Magneet: ")); u8g2.print(magnet ? F("Ja") : F("Nee"));
    u8g2.sendBuffer();
    
    client.println(F("HTTP/1.1 200 OK\nContent-Type: text/html\nConnection: close\n"));
    client.println(F("<html><head><script src='https://cdn.jsdelivr.net/npm/chart.js'></script></head><body>"));
    client.println(F("<canvas id='chart'></canvas><script>"));
    client.println(F("async function fetchData() { fetch('/data').then(r => r.json()).then(updateChart); }"));
    client.println(F("function updateChart(d) { let t = new Date().toLocaleTimeString(); chart.data.labels.push(t);"));
    client.println(F("chart.data.datasets[0].data.push(d.lux); if (chart.data.labels.length > 20) { chart.data.labels.shift(); chart.data.datasets[0].data.shift(); } chart.update(); }"));
    client.println(F("setInterval(fetchData, 2000);"));
    client.println(F("const ctx = document.getElementById('chart').getContext('2d');"));
    client.println(F("const chart = new Chart(ctx, { type: 'line', data: { labels: [], datasets: [{ label: 'Licht', borderColor: 'blue', data: [] }] } } });"));
    client.println(F("</script></body></html>"));
    client.stop();
  };
};

btw i want to know the ip so i know it is connected

Try putting a 1 second delay() before printing the IP address. I would also print some text before the IP address so that you know that the code is running successfully

Which Arduino board are you using and what baud rate have you got the Serial monitor set to ?

What happens if you upload the code, open the Serial monitor and reset the Arduino ?