Last time I did a deep dive into this, found a few papers suggesting that it can be any salt imbalance (potassium, magnesium or calcium) that triggers cramps.
However, potassium and calcium are a lot more prevalent in standard diets so it's usually lack of magnesium that is the culprit.
If you're experiencing muscle cramps due to low magnesium then adding a supplement will almost certainly fix the problem.
If you're experiencing muscle cramps for another reason, it won't work, probably.
But supplements are cheap and low risk, so it's a good thing to try first.
A more accurate statement would be "there is no scientific proof that Mg works against cramps [absent a Mg deficiency]."