ESP not assigning static ip address

I'm trying to assign a static ip but its not working. what am i doing wrong?

//COM 8

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>


IPAddress staticIP(192, 168, 4, 10);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);  
IPAddress dns(8, 8, 8, 8);  

IPAddress Server(192, 168, 4, 1);

const char* ssid = "LCS";
const char* password = "a1b2c3d4";
char verifyStart[7];
char verifyEnd[7];
unsigned int localUdpPort = 4220;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets
int ServerPort = 4020;
struct packet {
  int local;
  int PWMValue;
};
packet localData;
WiFiUDP Udp;

unsigned long currentMillis = 0;
unsigned long packetDelay = 1000;


uint8_t Light1 = 5;
byte BUTTONDWN = 2;
byte BUTTONUP = 14;
uint16_t dutycycle = 1022;
//set ESP to 600Hz for performace
void setup() {
  Serial.begin(115200);
  analogWriteFreq(600);
  Serial.println();
  analogWrite(Light1, 1023);
  pinMode (BUTTONUP, INPUT_PULLUP);
  pinMode (BUTTONDWN, INPUT_PULLUP);
  WiFi.persistent(0);
  WiFi.softAPdisconnect();
  WiFi.mode(WIFI_STA);
  Serial.begin(115200);
  Serial.println();
  WiFi.setOutputPower(99.0);
  WiFi.setAutoConnect(true);
  WiFi.hostname("LCS-NODE1");
  WiFi.config(staticIP, subnet, gateway, dns);
  WiFi.begin(ssid, password);
  Serial.println(" connected");
  Udp.begin(localUdpPort);
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.println("Cone1cting TO LCS");
    }
  Serial.println("Connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());  
}

void sendPacket() {
  localData.PWMValue = dutycycle;
  const char delimiter[] = "NODE01";
  const char delimiter2[] = "01NODE";
  Udp.beginPacket(Server, ServerPort);
  Udp.write((const uint8_t *)delimiter, sizeof(delimiter) - 1);
  Udp.write((const uint8_t *)&localData, sizeof(localData));
  Udp.write((const uint8_t *)delimiter2, sizeof(delimiter2) - 1);
  Udp.endPacket();
  //dutycycle = dutycycle - 5;
}

void loop() {
  if (millis() - currentMillis >= packetDelay) {
    sendPacket();
    currentMillis = millis();
  }

  if (digitalRead(BUTTONUP) == LOW) {
    dutycycle = dutycycle + 10;
    Serial.println("up");
    Serial.println(dutycycle);
    delay(150);
  }
  if (digitalRead(BUTTONDWN) == LOW) {
    dutycycle = dutycycle - 10;
    Serial.println("down");
    Serial.println(dutycycle);
    delay(150);
  }
  analogWrite(Light1, dutycycle);


    int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
    int len = Udp.read(incomingPacket, 800);
    strncpy(verifyStart, (char*)incomingPacket, 6 );
    strncpy (verifyEnd, (char *)incomingPacket + len - 6 , 7 );
    Serial.println(verifyStart);
    Serial.println(verifyEnd);
    if (strcmp(verifyStart, "NODECM") == 0) {
    Serial.println("Node1 Command From Master");
    const char ACK[] = "ACKED1";
    Udp.beginPacket(Server, ServerPort);
    Udp.write((const uint8_t *)ACK, sizeof(ACK) - 1);
    //Udp.write((char*)&buffer, sizeof(buffer));
    Udp.endPacket();
    }
  }

  // delay(100);
}

You should set the gateway to match your network. IPAddress gateway(192, 168, 4, 1);That is probably not it, also since that is actually the default IP for an ESP Access point. Go to the network settings of a computer connected to the same network and lookup the gateway there, it will probably be either 1 of these 3 options

IPAddress gateway(192, 168, 4, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress gateway(10, 0, 0, 1);

And then set the static IP to an address within that gateway (this you sort of did, changing the last nr of the gateway)

The address settings are right. However i did manage to get it to work by not defining the dns in config. idk why but whatever dns is not important to me in the case nor is the gateway. and the server is running on the esp's default class c subnet. so the gateway is the server