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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25344 |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|