Are there any cons of using :FindService() instead of :GetService()?

Just being interested if someone already tried replacing all :GetService() calls with :FindService() calls: are there any issues with it or it’s nice thing to do?

I think it can do great for optimisation as you’ll save resources on retrieving service again and again as you just get already called one if it exists (that’s how I’ve understood an engine of it, please correct if smth’s wrong)

:GetService() will look for a service given by string. If it exists, it returns the service. If it doesn’t exist but the service required is valid, it will create the service and return it.
:FindService() will look for a service given by string. If it exists, it returns the service. If it doesn’t exist, it will return nil.

There is no real noticeable performance differences without purposely trying to benchmark them. I recommend creating the :GetService() variable at the top of your scripts and call them whenever necessary. This will be less prone to run into any errors unlike :FindService().

What do you mean by update? The Players object will be the same, and thus any references will be the same, before or after a player joins.

You are right. I based my original reply off of DevForum posts and reading through the Engine API, and despite that, my example of the Player instance was wrong. I sadly also did not mention any of my sources to see where I went wrong.

Whereas the ‘updating’ that I mentioned was going in the right direction. To clarify, some services are excluded from the client and/or server when running. Hence utilizing :FindService() on said services will return nil. When there is the chance you need those services that are unavailable to the client or server side, you can use :GetService() to access it because of the function that this command has to ‘create’ the service once requested. This also applies to services that have been renamed. :GetService() will – despite the change of names – still return the appropriate service, which :FindService() will not, requiring you to give the specific name that it was changed to as input.

Small example with creating a service.
local service = "MemStorageService"

local find = game:FindService(service)
print(find) --//nil

local get = game:GetService(service)
print(get) --//MemStorageService

local find2 = game:FindService(service)
print(find2) --//MemStorageService

Same result for Client- and ServerScript.


I have edited my previous post to avoid confusion. Thanks for letting me know.

Yes, as far as I can tell a service is either created (either on the client or the server) or not. If a service has not been created yet in a certain context (client/server), then :GetService() must be used, otherwise :FindService() may be used. But I have never heard of there being some ‘update’ thing besides the service already having been created or not.