If you've still got the obstacle sensor attached, remove it and attach the magnet module again underneath.
The magnet module actually has sensors on that point down towards the floor that can detect lines, so it's actually mainly used as a line sensor.
N.B. You can't use the obstacle sensor on top and the line sensor underneath at the same time. These modules both use the same input/output 'pins'.