Is there any major benefit in using :GetService() on services such as ReplicatedStorage, ServerStorage, Players, and other containers?

Is there any major benefit in using :GetService() on services such as ReplicatedStorage, ServerStorage, Players, and other containers? Of course, the difference in typing

game:GetService("ServerStorage")

and

game.ServerStorage

isn’t a very big deal. The exception, however, is that we don’t get any intelisense (is that what it’s called?) suggestions for the container’s children if we use :GetService() as opposed to just writing the path.

4 Likes

GetService is the recommended method of getting services because if the service exists, it will fetch it, otherwise it will create and return it. Some services need to be created before they can be used. Additionally if the service name is ever changed, or has a different instance name, using GetService will still allow the service to be fetched.

11 Likes

GetService is canonical. Do not use anything else.

Outside of being the 100% correct way to do it, some, especially new, services are not guaranteed to be named by their Instance name (like RunService and UserInputService). GetService will also create the service, but I’ve never had a scenario where the service didn’t exist. The correctness is what you should be focused on.

11 Likes

I understand the importance if :GetService() for those services. I was specifically asking about the primary “container” services that you see in the explorer such as ServerStorage, ReplicatedStorage, and Players.

In any case, my question has been answered, so thank you!

2 Likes