You haven't given us much to work with. Perhaps you could describe what you have done, the type of fixture exactly, how it is fastened to joists/rafters??? whatever. Even a picture would help us understand what you are facing.
Here is a video showing the installation of a recessed light
You may want to search and watch more images and videos to get an idea of what is involved and how others may have addressed the problem you have.