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

I want to learn about game:GetService(). What do you use it for and why is it important?

I often see in scripts that it says:

local Camera = game:GetService("Camera")

What does that mean? I am new to scripting so I want to learn what it actually is.

Sincerely,

Ducksneedhelp

4 comments

0

A service is an object containing built in properties, built in functions, and built in events. The children of game ARE services. (workspace, players, lighting, starterpack, etc.) Services are just to speed coding up most of the time, otherwise it would take forever to write all the code. For example, "MarketplaceService" and "GamepassService" trigger events which will start code and functions.

0

Roblox builds in these services so that we skip writing a lot of code. There are different types of services, services you find in explorer, they are added automatically to your game. There are services that arent automatically put into your game. Remember when I talked about "GamepassService"? I only said it triggers events which will start code and functions. I didn't say properties.

0

We use the auto gen for their properties mainly, whilst we use other services for their events and functions mainly. They don't always have the most useful properties, but in some scenarios you may use the properties of other functions. You use game:GetService("insertservice") to get those services.

0

Thank you for letting me know about game:GetService()! I've wanted learn from Alvinblox, but I can't understand that. It would not work to tell this on Devforum, but luckily I can ask it here. Thank you!

3 answers

✓ Accepted answer

So, basically what :GetService() does is it gets the service of, let's say MarketplaceService. What you can't do is game.MarketplaceService. It's exactly what it says -- get's the service. In your case, you can also do game.Camera because Camera is already there. Things that aren't there, like MarketplaceService, need to be added with the :GetService() function. Happy to help, b_mni.

1 comment

0

Good to know some more of game:GetSerive()! Good thing is that everyone tells different stuff about it but also very close to the same. I enjoy everyones help, and they've helped me alot. Thank you!

game:GetService() is used to get a service, like game.Workspace. However, it's possible a service won't be loaded yet and therefore game:GetService() will load it, you could also change a service name. i.e. 'Workspace' -> 'Workplace' as an example. If you use game:GetService("Workspace"), it will still load the workspace even though its name is changed.

1 comment

0

Good for letting me know about some stuff about game:GetService()

All of the answers above / last answers are great but it has some left outs in information . True using the method game:GetService() is faster and better in anyway shape or form but why do people use it? For speed? Easier? Yes to all of that but as you know there's another thing example as JailBreak it changes the workspace,players,replicatedstorage,etc's name every second or so so there's not a way to keep track unless it's kept by the script so people use game:GetService() to get the worskapce,players,etc because there's no other way if it keeps changing the name.

1 comment

0

Thank you for some informaion!

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