This is a common problem with the Moto G4. The first step to fixing this issue is to try and identify what the cause of the restarting is.