Difference between game:GetService("Players") and game.Players

Hello there! When I see others code, I see that some people use GetService() to get instances like Players,ServerStorage etc. But I don’t understand that if it’s much easier just to get service with game.Service. Who can explain?

Preference mainly. Using GetService will allow you to no matter what get the service, even if the name gets changed by either you or an exploiter, while if the name was changed and you used game.Players then you would get an error. GetService is best practice.

4 Likes

If exploiter changes the service name,the game will break and exploiter will leave. Or I understand that not correctly? And also only local script will break.

1 Like

If somehow some way the name of the Players service in the explorer tab is changed then game.Players won’t work, however, 'game:GetService(“Players”)` will still work. Same thing goes for other services such as ServerStorage, Lighting, etc.

Just to add on, GetService can also be used for services that are not descendants of the game instance - such as UserInputService. In this case game.UserInputService would error.

2 Likes

It’s somewhat implicit in these words, but this is the server side, so this:

cannot happen, the exploiter can’t change anything related to the server unless there is a backdoor. Why would any exploiter want to break client sided code? If the game is safe enough, that can’t give them any advantages.

1 Like

This is false. Even if exploiters change the name of for example workspace it will still work.
GetService is pretty much useless and if exploiter wanted to break your scripts he could hook function GetService and break it anyways.

It doesn’t matter if it is changed locally or on server. Nothing will break.

Edit: as bobbybob2131 stated GetService can be used for for example getting services not under game.

1 Like

I had a similar post a while back and had some pretty insightful answers, feel free to check it out game.Players vs. game:GetService("Players") - #17 by Halalaluyafail3