Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between finding a child of game normally and using :GetService?

Asked by 4 years ago
Edited 4 years ago

So I've been looking at some scripts and they were using :GetService instead of doing game. , here are some examples:

--StarterGui
game:GetService("StarterGui")
game.StarterGui
--RP
game:GetService("ReplicatedStorage")
game.ReplicatedStorage
--Workspace
game:GetService("Workspace")
game.Workspace
workspace
--SS
game:GetService("ServerStorage")
game.ServerStorage

From what I know, you can do that for any child of game. Can someone please explain to me if there is any difference?

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

I recommend GetService as some people like to change the name of their core services in game.

For example, some people would change ReplicatedStorage to RepSto. Then, if you try to use game.ReplicatedStorage it wouldn't work, because it looks for the name, not the service. On the other hand, if you do game:GetService("ReplicatedStorage"), even if the name is RepSto, it will look for the service associated with the class.

But, if you don't change your game services' names, you can do game.ServiceName.

All in all, I recommend getting into the habit of using game:GetService("Service Name").

Hope this cleared things up and helped you!

0
Thanks. I didn't even know you can change the name of core services. User#32819 0 — 4y
1
No problem! Glad to be of help! We always learn something new everyday! killerbrenden 1537 — 4y
Ad

Answer this question