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

What is the meaning of GetService? vs No GetService?

So i have been scripting and have seen people use

game:GetService('Players')

that is just one example, but i have always done it like

game.Players

Does this only work because im in experimental mode? does FE change this?

2 comments

0

some time in normal server if your code have something like "game.ServerStorage" then it can give a error like "ServerStorage is not a valid member of DataModel" but if your code have "game:GetService("ServerStorage")" then the script will work fine, In experimental mode both looks same but if you publish the place and play it with roblox player then it make deference.

2 answers

game:GetService("Players")

Is like

:waitForChild()

It waits for the service to be ready, while,

game.Players

Simply references the service.

Well, it's kinda weird. Let me try to explain.

The game has tons of "Services" like Players, the one you mentioned. It has other services, such as TweenService, RunService, etc etc etc. GetService() Finds these services, and if they don't exist, it creates a new one. It gets a bit more complicated, i.e. this Reddit post shows how using GetService() can differ from just using game.ServiceName. But, basically, it usually won't matter if you use GetService or not.

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