Is GetService Even Necessary?

Hey, this is a short topic i was just wondering if using GetService is necessary like can’t i just use game.Server just like how you access a child through a parent in a script?

1 Like

:GetService() is most certainly necessary. Say for instance you want to get the “RunService” service. If you use local RunService = game.RunService, there’s a chance that you will receive an error because the service has not loaded in yet, especially if there’s a lot in your game to load in. :GetService() prevents this error by creating the service in case if it does not exist yet. local RunService = game:GetService("RunService")

I hope that helped you!

1 Like

Is there any difference if you reference, for example, ReplicatedStorage with:

game:WaitForChild("ReplicatedStorage")
1 Like

WaitForChild() will wait for it to be created, which pauses the script and might throw an error if it takes too long, GetService() will create the service if it doesn’t exist yet and will not pause the script.

1 Like

Alright thanks for letting me know

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.