I'm confused about these two variables, don't they do the same thing? Sorry if this is obvious, I'm new to scripting.
local players = game:GetService("Players")
and
local players = game.Players.LocalPlayer
I'm confused about these two variables, don't they do the same thing? Sorry if this is obvious, I'm new to scripting.
local players = game:GetService("Players")
and
local players = game.Players.LocalPlayer
This discussion is preserved as it was. New answers, comments, and votes are closed.
5 comments
https://scriptinghelpers.org/questions/96619/what-is-the-difference-between-finding-a-child-of-game-normally-and-using-getservice#89257
It's a good habit to use :GetService() instead of game.ServiceName
Oh I see, but just to be sure they both accomplish the same thing?
Yes, they accomplish the same thing. You just can't always promise that each service is going to load in on time. For example, if you're referencing the Players service in a script which runs as soon as the game starts, Players may not be considered a valid member yet since it hasn't loaded in. :GetService will wait until it has loaded in though.
I understand now, thank you