俺以外の奴がいると出ないってことなのか、 あるいは何かあったときのためにと 電気をつけっぱなしでいるのが悪いのか。
Context: The main character told one of his roommates that a ghost has been appearing in his room. So now they are sitting in his room together, but the ghost/weird stuff are not happening.
I understand:
俺以外の奴がいると出ないってことなのか、
Is akin to "one of the possibilities is that it's because there is someone other than me in the room"
あるいは何かあったときのためにと 電気をつけっぱなしでいるのが悪いのか。
However, I'm struggling to parse the second sentence.
電気をつけっぱなしでいるのが悪いのか。
Seem to be "The fault may lie in the fact that the lights are left on"
But then, how is あるいは何かあったときのためにと acting in this sentence?
Particularly I'm stuck with the nuance of ためにと. I think ために is "Because of..." but how is the と here used? I far I understand, the first part "あるいは何かあった" is "Or else something happened".
