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

Is :GetService() only supposed to be used with particular services or all of them?

Asked by
Rinpix 639 Moderation Voter
4 years ago

Habitually, I pretty much always use :GetService().

I only know that it's conventional to always use the function :GetService(), and not the particular reason why. I've looked at posts that people have made asking the same question, but the answers seem to be all over the place.

Is :GetService() only used with services that aren't already given to you in the explorer?

Or is it just used as a precautionary measure to load the service if it hasn't loaded already, regardless of whether or not it's a service already given to you in the explorer?

The reason I want to know this is because simply indexing a service without using the function involves a lot less typing.

0
Getservice like the name suggests gets a service like the lists of service in the explorer. JesseSong 3916 — 4y
0
you can get my service ;) greatneil80 2647 — 4y
0
?? JesseSong 3916 — 4y
1
Basically you are free to use either game.<servicename> to any services that are in the explorer. its not important if u used game.GetService() on a service that is already in the explorer its meant for both visible services in the explorer and the ones that aren’t. Baselistic 103 — 4y
0
I know what :GetService() does, but I don't know exactly when it's intended to be used. Rinpix 639 — 4y

3 answers

Log in to vote
1
Answered by
ScuffedAI 435 Moderation Voter
4 years ago

A simple search reveals an devforum post similar to this.

GetService is mainly used for services that aren’t guaranteed to be instantiated, like Teams and InsertService. For Players, it is fine to not use it, but you may get one complaint from an error “Players is not a valid member of game” because they have the Players service renamed if someone who doesn’t know what they are doing uses your code. If it is private code and Players isn’t renamed, there is no difference.

link to original post

0
For some reason I couldn't find that earlier when I was searching around. Thanks. Rinpix 639 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

GetService(ServiceName) is similar to game.ServiceName..

0
uhhhhhhh, why is this downvoted?? this also indexes a service -_- User#23252 26 — 4y
0
I didn't down vote it, but I'd say it's because of the lack of an elaborate explanation. Rinpix 639 — 4y
0
his asking for the whether or not the 2 syntax are the same.. User#23252 26 — 4y
0
the small things in life makes sense to me.. ill give this dude an upvote greatneil80 2647 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

:GetService() can be used with any service. As you said, it's actually better than saying game.Players or whatever your service is called. It's better since it checks if the service isn't nil. If it is, it makes/gets the service. To answer your question, yes. They can be used with any service you want.

0
What I want to know is if it's necessary to do something like game:GetService("Lighting"). Is there ever a chance that Lighting isn't already loaded? Rinpix 639 — 4y
0
Well, i guess you could use game.Lighting for services in the explorer. youtubemasterWOW 2741 — 4y

Answer this question