some developers use game.Debris instead of game:GetService("Debris")
does anyone know why they do that and atleast give me the closest answer and also which one should i use
some developers use game.Debris instead of game:GetService("Debris")
does anyone know why they do that and atleast give me the closest answer and also which one should i use
It really doesn’t matter to be fair, you can use both, and it applies to all services, though game:GetService("Debris") is better practice. As services can be renamed(at least all the ones in the explorer im pretty sure), and using game:GetService("Debris") keeps all the behaviour consistent, even when that service was being messed around with.
Some services are not guaranteed to exist so indexing them directly can error. Using GetService will avoid that issue and automatically handle the creation of services for you. There are more downsides for directly indexing an instance such as renaming (as mentioned above) or getting the wrong instance if you have multiple instances with the same name. On the other hand, there is no reason not to use GetService.
I used this version for all those kinds of setups for the reason D1CEL pointed out. I have had the other way rarely fail, but the GetService version for all those kinds of things has always been solid. So that’s where I’ll stay.
Indexing services is unsafe and slower
Always use :GetService
Same with :IsA()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.