Why do people use game:GetService() for services not shown in the explorer?

:confused: It is not a tradition, it is a good practice. Doing game.ServiceName is indexing a property of a datamodel, this is bad because of multitude of reasons. Just think of doing game:GetService has no consequences, while game.Service does.

Then why do the same people do game.ShownServiceName?

1 Like

Probably because they don’t know as much as experienced programmers…

1 Like

This is almost 100% tradition, while also being a good practice, I never learned that I should use one over the other and so I just use game.Workspace or game:GetService(“HttpService”)

1 Like

workspace is a global, which you shouldn’t be using either lol.

In addition, it’s not really taxing and doesn’t change much.

For most developers, it’s just a (bad) habit. The recommended way to access services is via game:GetService; with the exception of Workspace, which has its own global variable (workspace).

You can make hidden services visible in the Explorer under Studio Settings.

I just use workspace because it has syntax highlighting and it is shorter.

Maybe you should start doing what’s good practice… If you didn’t know game.Workspace is a property of game. What does this mean? An exploiter could for example reassign Workspace’s name locally and make some scripts error. game:GetService(“Workspace”) will always return correctly.

I don’t see how this is that big of a deal, an exploiter can literally change anything locally if it can be changed locally.

An exploiter cannot do changes to the server? Filtering Enabled stops that. An exploit is a local script. Edit: I re read what you said and it still does not make sense. It won’t replicate therefore it won’t do any damage. Edit2: Also I am only talking about hidden services, people do game:GetService(‘HiddenService’) but not game.HiddenService (I do mostly use game:GetService(‘Players’) besides workspace)

1 Like

The key word here is locally. This means it only happens on the client. This can still cause damage to some local scripts.

1 Like

I’m not saying that you shouldn’t use GetService. It just isn’t really that big of a deal and it’s fine to use either.

Try reading my second edit, I do use GetService on everything besides workspace, I just want to know why people always use GetService on hidden services than shown services.

Your scripts shouldn’t just break when a service is renamed…it’s literally bad practice to use . indexing to get children anyway. Your code is assuming Roblox won’t add a class member with that name. Remember that members have precedence over children, so when you do workspace.Terrain you are actually accessing the Terrain property of Workspace, not the child. Now imagine if for some odd reason Roblox adds a property called HttpService to the DataModel, your scripts are broken. Why do people directly index for HttpService? I don’t know. There are a million reasons as to why. It could be because they stubbed their toe. Or because their hair is brown. But the most probable is seeing other people do it.

2 Likes

Try reading my post above yours came out at a pretty bad timing lol

i think getservice for workspace is a good thing for a anti cheat in client while u change the workspace name or every service making it error and detect it by the ScriptContext for some executor’s you can grab the workspace by getservice correct me if i am wrong

You’re not understanding, your local scripts would break. They shouldn’t just break. And I was already writing mine

Actually, it does not matter if you change the name, you can still use game.Workspace for some reason (not on other services)

I said that I use getservice in my post above, I don’t get why people use game.ShownService but use game:GetService(‘HiddenService’)