depends on the cheese, but most often your problem is acid.
Higher acid cheese do not melt, the best melting cheeses are washed curd types such as Raclette which have a high pH because whey has been removed and replaced with water. long aged Alpine types, for example, never melt very well and often don't taste good once melted, this because the pH is low.
Other times, it could be over dry curd -which is caused normally by to strong rennet or too much time in the make after rennet is added.
Other times, the problem is a broken protein structure, which is caused by pasteurizing and homogenizing milk.
Examine your procedures and identify which of these is most likely to be your problem. If you want a good melting cheese, try adding some water at some point in the make after cutting the curd to raise the pH, even if the original recipe doesn't call for this (makers of Emmentaler have used this trick for, I don't know, 300 years or so, even though no Emmentaler recipe I have ever seen calls for it)