There is a lot going on in that code block, so I'm going to go over each piece.
ROBLOX Events (Touched, KeyDown, RenderStepped, etc.) use callbacks to function. These callbacks are passed specific arguments depending on the event. For instance, Touched passed the part that caused the Touched event to fire.
The syntax for setting up an event callback has two forms, both of which are used in your code block:
nP.Chatted:connect(function(msg)
game.Players.PlayerAdded:connect(onPlayerEntered)
The first is anonymous, the second, named. This works due to something called first-class functions, but that is beyond the scope of this answer.
The difference to notice is that the anonymous version has the function defined inside of the call to connect, whereas the named version has it defined elsewhere, and passed in like any other variable.
In the case of the PlayerAdded event, only one this is returned: the Player object that is created when the event has been fired. Note the difference in spelling from the Players service.
The Player object has many methods and events, one of which is Chatted. As indicated on the linked page, it returns two things: the message being sent, and the Player object of the 'recipient'. The latter will always be nil unless the whisper functionality of ROBLOX chat it used, in which case it will be the Player whispered.
To summarize: PlayerAdded passes in the Player object that was added when the event fired to the given callback function, which is OnPlayerEntered.
This Player object is captured using the parameter nP, and itself has an event called Chatted that is given an anonymous callback. This anonymous function is passed the message being said, and the Player object, if any, being whispered.
If you ever come across an unfamiliar event, look it up on the wiki! If that fails, definitely ask some questions here.
3 comments
Alright thanks I'm starting to understand it a bit more. If I do need more help about something related to this would you mind if I PMed you through roblox?
No, I wouldn't mind!
Ahh I was assinging it like local var = ... not {...}