How to damage player if he is outside of a part

Try using the ZonePlus module since I believe it matches what you need. The documentation and the simple examples ForeverHD gives in the post should be enough to tell you how

Detect when player leaves zone and start damaging them until they enter back