For a little while now, I’ve seen people use game:GetService() on something like Lighting, or StarterGui. However, I find that pointless due to the fact that you can just get the path of it from the explorer.
Example:
-- Getting its service
local StarterGui = game:GetService("StarterGui")
-- Getting its path
game.StarterGui
And I’d like to know…are they any advantages to getting its service rather than simply using the object’s path?
Using the dot notation finds the first instance with the given name, so if you rename your service or something else happens that somehow renames a service to another service, it would error/give the wrong service. Whereas GetService uses ClassName lookup so it ensures you get the right service if you input the correct ClassName
If the service you’re trying to obtain does not exist by the time you run GetService, it will create the service and return it, dot notation does not do this and will error
Some services have names different from their class name, example, RunService is the ClassName and Run Service is the actual name of the service
Generally, GetService is the safer and more recommended method to getting a service for usage