I have pain on my testicles when I do sex?

Many causes. This is a very common and usually self limited condition. It usually resolves over time or may require treatment such as antibiotics or analgesics. A scrotal ultrasound is recommended to rule out malignancy. If all studies are normal, then one can use a scrotal support and sitz bath to help wit the discomfort. Taking an analgesic prior to intercourse may also decrease the pain afterwards.
See a doctor. So many causes for testicular pain with sex. It could be your prostate, epididymis or testicles. See a urologist.