Which would be more efficient to use when a server is starting up?
Currently, I have a fairly huge game that’s very lag intensive when the first player joins.
Is it more efficient to use:
game:WaitForChild("Lighting")
or
game:GetService("Lighting")
I’d rather wait for the service to be loaded in rather than spawning it in. Does it really matter though?
For further info: GetService will create the service if it’s not there. For instance, game:GetService("Teams") will create the Teams service if it’s not there.
It’s also useful because it’s tied to the class, not the actual name. You can rename services but still use GetService on the classname.
I don’t find this necessary, I use game:GetService() for all services, for consistency’s sake if nothing else. It will return the service if it has already been created, so no real downside.
You should always use GetService for indexing services. Allow me to explain why not WaitForChild:
The server has most services implicitly loaded, so waiting for them is pointless.
Services not created on run-time cannot be indexed.
Consistency’s sake. A lot of your projects or collaborators, if any, will use GetService.
Some hidden services are named “Instance”, not their actual name. GetService will fetch them by ClassName whereas WaitForChild explicitly does it by name.
Cases where services use whitespace, such as RunService: game["Run Service"] vs game:GetService("RunService")
Services can be renamed. You shouldn’t ever be renaming services and it’s stupid to account for name changes, but there are inconsistencies such as for SoundService (some projects have it as Soundscape, whereas others have it as SoundService)