generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: :GetService() over game.ServiceName

Previous Thread :: Next Thread 
dave2011 is not online. dave2011
Joined: 02 Oct 2010
Total Posts: 10581
16 May 2016 11:03 PM
is there any purpose for this besides if I were to rename the services (which im not going to)


Report Abuse
GetTheJobDone is not online. GetTheJobDone
Joined: 20 Apr 2016
Total Posts: 3008
16 May 2016 11:06 PM
If ROBLOX were in theory to change the name of a service. Basically, not gonna happen. Only necessary for services like Debris.


Report Abuse
AVeryNerdyDude is not online. AVeryNerdyDude
Joined: 17 Apr 2009
Total Posts: 2163
16 May 2016 11:14 PM
It is good practice to use :GetService rather than game.ServiceName. :GetService, in my opinion, is safer than just going

game.Players

or

game.HttpService

plus it looks nicer, and more neat and helps distinguish between services and variables.


#code ypcall(function() workspace.SuspiciousItems:Destroy() end)
Report Abuse
2eggnog is not online. 2eggnog
Joined: 08 Nov 2008
Total Posts: 1351
16 May 2016 11:14 PM
Sometimes a service isn't available right away, which will cause an error. Using GetService prevents that problem from happening.


Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
16 May 2016 11:15 PM
What 2eggnog said
Report Abuse
gskw is not online. gskw
Joined: 05 Jan 2013
Total Posts: 1364
17 May 2016 07:39 AM
I would prefer game:GetService "RunService" over game["Run Service"]
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
17 May 2016 08:05 AM
If a hacker changes a service name your whole game breaks
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
17 May 2016 08:26 AM
:GetService() was implemented because not all services are available in the moment. That is only one side of it. Not all services are even created. Plus, it looks neater.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 May 2016 09:05 AM
if your script is this(for example):

local players = game.Players
local player = players.LocalPlayer

and then somehow the Players object's name got changed, your script would break

--

no matter how unlikely you think that is, you can prevent future incidents by always deriving from GetService.

local players = game:GetService("Players")
local player = players.LocalPlayer

as the name implies, it gets the actual service from deep within roblox instead of trying to find it within the game hierarchy
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
17 May 2016 09:08 AM
cody brought up a better point tho

--

local UIS = game:GetService("UserInputService")

because some services you have to create

so why not just be uniform?
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 May 2016 09:51 AM
The only reason you need to use game:GetService() are for the services not available in the roblox game upon playing. For instance. You can do, game.Workspace,game.Lighting,game.ServerStorage but you will need to load the services not in the game such as UserInputService, RunService,InsertService etc. Thats my philospohy. There is literally no point in doing game:GetService("ServerStorage") when its already there in the data model.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image