Aim at mouse error

I'm using the following script to aim using the mouse at the screen but sometimes the aim device doesn't follow it and stays looking in the same direction. I believe it's due to the mouse position exceeding the screens height and width positions but I can't be sure...Is there anyway to fix this?

I'm using a cube as the firing point for the shots.

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
       AimingTarget = hit.point;

All I can think of is that the ray is not hitting a collider... you could try adding more colliders to the empty parts of the scene.

hope this helps!