You could do a raycast from the beam start and forward - when the raycast hits an object, save that as a variable and calculate the distance between it and the player, and then determine the beams length from the distance between the player and the object the beam "hits"
Just off the top of my head, dunno if this would work - worth a shot though