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

What does getservice()?

Asked by 8 years ago

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

1
Not exactly sure how to explain it, but you can use it like game:GetService("Teams"). ISellCows 2 — 8y
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. RadiantSolarium 35 — 8y

2 answers

Log in to vote
4
Answered by 8 years ago

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.

Ad
Log in to vote
0
Answered by 8 years ago

:GetService() is something you run when you want to get a service that can not be accessed by game.<namehere> E.G game:GetService("MarketplaceService") gets the ROBLOX 'marketplace' (where you buy stuff like clothing). http://wiki.roblox.com/index.php?title=GetService

0
Also HttpService! NeonicPlasma 181 — 8y

Answer this question