Hello and welcome.
-Which exact model of MacBook?
-Does it intermittently go on and off if you move the screen back and forth?
It could be a coupe of things causing that - display cable is worn, battery is nearing the end of its life cycle, temperature issue, software issue.
We can go though each of them once we know the full model.
C