I would like to know if there is any tangible difference between using :GetService()
and not. In the example scripts Roblox provides, they always use :GetService()
. I have always assumed there is some performance-improving reason for using :GetService()
, but I have never found one. Are there any drawbacks to just doing game.service
instead of :GetService()
?
Have a look at this post:
Please always use game:GetService
when getting services. It is considered the canonical method.
7 Likes
Could you elaborate on why it is preferred? Is it just that, “GetService is mainly used for services that aren’t guaranteed to be instantiated” and renaming as Nexus said, or is there further reasoning?
By using game:GetService("ServiceName")
it creates the requested service if it doesn’t already exist whereas game.ServiceName
will get the service but if it doesn’t exist it will return an error instead of creating it.
In conclusion, it’s better practice to use game:GetService("ServiceName")
when getting services.
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.