Raycast shooting script

Hi, im having a problem with my raycast shooting script, i have this script set up on an empty gameobject at the barrel of the gun. For some reason the script make it spawn bullet holes in really wierd places, got an idea?

#pragma strict
var bulletHole : GameObject;
function Update () {
 var fwd = transform.TransformDirection(Vector3.forward);
 var hit : RaycastHit;
 Debug.DrawRay(transform.position, fwd*10, Color.green);
 
  if(Input.GetButtonDown("Fire1") && Physics.Raycast(transform.position, fwd, hit, 10)){
     Instantiate(bulletHole) hit.point Quaternion.FromToRotation(Vector3.up, hit.normal);
     }
}

Wrong place and wrong rotation are two different questions. This part of the code you originally posted takes care of the alignment:

 Quaternion.FromToRotation(Vector3.up, hit.normal)

This code assumes the bullet hole was on a plane facing up when the rotation is (0,0,0). If you are using a Quad, then substitute Vector3.back.

You can also do it after the instantiate.

  var go = Instantiate(bulletHole, hit.point, Quaternion.identity);
  go.transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * go.transform.rotation;

You need to substitute for ‘transform.up’ whatever side of the object is the face. But the prefab can have an arbitrary rotation, and this code will do the alignment.