Okay, so I am studying the Japanese language and i am struggling to understand the に and で particles fully. from what i understand the de particle shows an action happening within a location, while ni shows the 'existence' of something or a specific direction something goes in. My two examples being ライブラリで眠った (i fell asleep in the library) and ライブラリにだった (i was in the library(is it right to use datta? or should it be ita?)). Not sure if the sentence is 100% but are they the correct particles in context?
You're on the right track. Off the top of my head, で denotes action at a location, can also be used to connect multiple clauses in a sentence, means of an action, and also cause of effect. に on the other hand is used for direction of a subject, existence of a subject, or action at an event. For the most part it should be relatively easy to distinguish when to use the two.
action at a location 公園で遊んだ (I played at the park)
connect multiple clauses in a sentence うどんは日本の名物で美味しい。(Udon is popular Japanese product and is delicious)
means of an action 車で学校へ行く。 (I go to school by car)
cause of effect 大雪で行かなかった。 (I didn't go because of\due to heavy snow)
direction of a subject デパートに行った。(I went to the department store)
existence of a subject 家にいる。(I'm at home)
action at an event 試合に勝って勝負に負けた。(I won the match but lost the contest. Similar to saying winning a battle but losing the war)
The last example uses に twice to emphasize how you would use it in an action. It would sound weird to insert で instead of に because the action happened at an event and not a location.
your are right but you asked ライブラリにだった(I was in the library) is wrong you should use ita...iru is a verb used for human and animated things. desu(datta) is a sentence ending particle..