This is 100% caused by the way the code is executed. You need to structure it in a way that if it does fail it will simply try again on the next loop. Here is an example of one of my banking methods:
if (!script.inventory.contains("Coins")) {
if (!Banks.LUMBRIDGE_UPPER.contains(script.myPosition())) {
script.getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
} else {
if (!script.getBank().isOpen()) {
if (script.getBank().open()) {
Sleep.sleepUntil(() -> script.getBank().isOpen(), Script.random(5000, 10000));
}
} else {
if (script.getBank().contains("Coins")) {
if (script.getBank().withdrawAll("Coins")) {
Sleep.sleepUntil(() -> script.inventory.contains("Coins"), Script.random(5000, 10000));
}
} else {
script.stop(false);
}
}
}
}