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

What does getservice()?

I'm not sure what getservice() does but if maybe you can explain that would be nice.

--maybe like this?

local Button = script.Parent.Button
Button:getservice()
---I'm really sorry I need help

2 comments

1

Not exactly sure how to explain it, but you can use it like game:GetService("Teams").

1

I mean, YEESH people! ONE incorrect answer! Just TELL me, rather than make me lose almost HALF of my hard-earned reputation! I mean, come ON! WHY?! I mean, it's not on purpose, and if it was, then sure.

2 answers

✓ Accepted answer

Most services are direct children of game. However, not all of them are, and some might not exist when your game is run. In those cases, you need to use GetService to access those services. We can simplify down GetService and say it has two uses:

The first use is getting a hold of services when you cannot access it through game.ServiceName. For instance, UserInputService is not a child of game, so whenever you want to use it you must access it through game:GetService("UserInputService"). I would also be unable to access the lighting through game.Lighting if I had renamed it to something other than "Lighting". If a service has had its name changed and your script doesn't know what the new name is, the only way you can access it is through GetService.

The second use is for loading services that are not currently loaded. The only services I know aren't loaded by default off the top of my head are TestService and Teams, but there are probably more. In TestService's case, you need to use game:GetService("TestService") to create it. You also might have a service that somehow gets deleted and you need to re-create it.

The wiki has a list of all services if you're interested in how many there are and what they do. At the bottom of the page, all of the items under "Services" are services, and some under the "Containers" section are services as well. Services are used very frequently in scripting, from prompting the player to purchase items to reading input from their keyboard and mouse, so you need to make sure you know how to use them. You've probably already used some without knowing though. Workspace, Lighting, and Players are all services. Invoking game.Players:GetPlayers() is using a service.

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