How can I make my code more efficient?

Hey, can anybody please help me make my code more efficient?
I don’t know if this is good or bad but 31% doesn’t seem too good for a fairly basic script.
image

My Code
const playerId = PlayerId();

on("playerSpawned", (spawnInfo) => {
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_HILLBILLY"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_BALLAS"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_MEXICAN"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_FAMILY"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_MARABUNTE"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(
    1,
    GetHashKey("AMBIENT_GANG_SALVA"),
    GetHashKey("PLAYER")
  );
  SetRelationshipBetweenGroups(1, GetHashKey("GANG_1"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("GANG_2"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("GANG_9"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("GANG_10"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("FIREMAN"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("MEDIC"), GetHashKey("PLAYER"));
  SetRelationshipBetweenGroups(1, GetHashKey("COP"), GetHashKey("PLAYER"));

  for (i = 1; i <= 15; i++) {
    EnableDispatchService(i, false);
  }
  SetAudioFlag("PoliceScannerDisabled", true);
});

setTick(async () => {
  const playerPed = GetPlayerPed(-1);
  const playerCoords = GetEntityCoords(playerPed);

  if (GetPlayerWantedLevel(playerId) != 0) {
    SetPlayerWantedLevel(playerId, 0, false);
    SetPlayerWantedLevelNow(PlayerId());
  }

  ClearAreaOfCops(playerCoords.x, playerCoords.y, playerCoords.z, 420);
});

You could use SetMaxWantedLevel - FiveM Natives @ Cfx.re Docs instead of looping the wanted level check

1 Like

That doesn’t work for some reason, I have tried using that but it doesn’t change anything wanted level can still go up.