When you use "which" in a sentence, it is part of a relative clause, directly modifying the word or words that precede it:
Example: The television series, "Law & Order", which is a popular crime drama, often explains various aspects of the criminal justice system.
Notice the comma that precedes the word "which" in the example. If you took the relative clause, "which is a popular crime drama, the sentence still makes sense.
When you use "that" in a sentence, it is also a modifier, but it is not part of a relative clause. It adds information about the noun it follows.
Example: "Can you please grab the green book that is at the top of the bookcase?"
Notice that no comma is needed in this sentence. The word preceding the phrase, "that is at the top of the bookcase" is the noun "book", to which the word "that" directly refers. It tells us the particular book the speaker is asking someone to grab.
This leads me to the other function of the word "that." When used as a definite article (a modifier), it refers to a specific item.
That magic wand belongs to the sorcerer.
That tire is heavy and hard to carry.
A simple test you can use to determine whether to use "which" or "that" is to check the meaning of the sentence when you take out the clause in question. If the clause points to information that is essential to the meaning of the sentence, then you would use "that". If the clause is used to enhance without taking anything away from the meaning of the sentence, then use "which". Eliminating the relative clause that begins with "which" does take out information, but not knowing that information doesn't affect our understanding of the sentence itself; the clause simply provides more detail about the words it modifies.