I know how the GetService() method works, and I use it. But from looking at the wiki I noticed that that are children of game (i.e. Workspace, Players, Teams) all have a GetService():
game:GetService("Players")
Is there a difference between
local players = game.Players:GetPlayers()
and
local players = game:GetService("Players"):GetPlayers()
Is one more efficient? Are they exactly the same?
Another question similar to this, is
local players = game.Players:GetPlayers()
the same as
local players = game.Players:GetChildern()
or is one better than the other?
The GetService method always returns a service given its class name. The significance of this is revealed when you think of the situations where this may be the only way to get a service. For example:
If you are creating code solely for yourself, you can get away with directly indexing from game (if it is appropriate for that service). However, if you are creating code that will be used by other people, you can save them a lot of headache if you use GetService by making sure your code works no matter what they do.
As for GetPlayers vs GetChildren, GetPlayers is useful for returning a table of players. The significance of this is revealed when you outline exactly what the two methods do:
Notice how these two are not the same in all cases. For example, the Players service may have children that are not necessarily players, but will still be part of the array returned by GetChildren.
There is an unwritten rule about the GetService method being more reliable, though I don't know why. Just use that one for now until someone can provide a better answer.
@aquathorn321 is right. It's considered good practice, and is much more reliable between testing on single player, local servers and Roblox servers. It's not just the Players service, all servers should be requested in this way.