local frame = script.Parent.Frame; local cam = workspace.CurrentCamera; game:GetService("RunService").RenderStepped:connect(function() local camCF = cam.CoordinateFrame; local xOffset = (frame.AbsolutePosition.X+(frame.AbsoluteSize.X/2)); local yOffset = (frame.AbsolutePosition.Y+(frame.AbsoluteSize.Y/2)); local depth = 6; workspace.Part.CFrame = CFrame.new(cam:ScreenPointToRay(xOffset, yOffset, depth).Origin); end);
The code above works well enough, except for when the object is moved to the sides of the screen.
As you can see from the image above, when I move the part to the sides, it moves closer to the screen making the part appear larger than it is. What's the best way to make it retain the same distance away from the screen no matter where I move the frame?