How can I make two players share a camera in code?

hmmm there possibility that you set is being overwritten later on, maybe try to st splitsceen configuration first and then set up 2nd player. Try diffrent events too