var/target = ref
if(ismob(ref) || isobj(ref)) target = ref:loc

if(first) first.loc = target
if(second) second.loc = target
if(third) third.loc = target
if(fourth) fourth.loc = target

Problem description:

hi, how would i make this code loc onto the mob which it is fighting? at the moment whenever i fight someone the numbers float above my head, which is really innoying because i dont know if thats my hit. how can i make it so that my damage goes on the enemys head not mine
I've almost no idea what that is all about. Explain more what you're trying to implement here and what that code is supposed to do, because it doesn't make sense. Why are you making a target variable instead of continuing to use ref? What are all those first,second objects? It looks like you may have whatever you're doing here designed improperly with them. Also, just define your variables types properly - don't use the ':' operator:
var/atom/ref = whatever
world << ref.loc

Something else you should change in your code is:
if(ismob(ref) || isobj(ref))

Both objs and mobs happen to belong to (be under, are a "child" of, etc) a node type called /atom/movable (which is in turn a child of /atom, of course). So you can replace that check with a single one (look up istype() as well if you're unaware of it):