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

5 comments

0

It's a good habit to use :GetService() instead of game.ServiceName

0

Oh I see, but just to be sure they both accomplish the same thing?

0

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.

0

I understand now, thank you