Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

5 comments

0

Getservice like the name suggests gets a service like the lists of service in the explorer.

0

you can get my service ;)

0

??

1

Basically you are free to use either game. 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.

0

I know what :GetService() does, but I don't know exactly when it's intended to be used.

3 answers

✓ Accepted answer

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

1 comment

0

For some reason I couldn't find that earlier when I was searching around. Thanks.

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

4 comments

0

uhhhhhhh, why is this downvoted?? this also indexes a service -_-

0

I didn't down vote it, but I'd say it's because of the lack of an elaborate explanation.

0

his asking for the whether or not the 2 syntax are the same..

0

the small things in life makes sense to me.. ill give this dude an upvote

: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.

2 comments

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?

0

Well, i guess you could use game.Lighting for services in the explorer.

This discussion is preserved as it was. New answers, comments, and votes are closed.