How to make a part that follows the mouse BUT can't go beyond 5 studs

So, I am currently making a game where you drag and drop items BUT I realized that the part would go too far away from the player to the point that it can’t be seen at all.

I want the part to ALWAYS follow the mouse once it is clicked and dragged around but with the only exception is that the part will never go away from the player in a 5 stud radius just like the building mechanic in 3008 as a reference but if the part is less than 5 studs away from the player (pointing at the ground) it will follow the cursor.

I am sorry if this sounds too specific but I just needed a lot of help for this one.


You could use Raycasts to calculate the distance between the Camera and the mouse position, with the distance of the raycast set to 5 studs.