Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between GettingService or just the Local Player?

Asked by 4 years ago
Edited 4 years ago

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
0
It's a good habit to use :GetService() instead of game.ServiceName killerbrenden 1537 — 4y
0
Oh I see, but just to be sure they both accomplish the same thing? WizardEpidemic 11 — 4y
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. AntiWorldliness 868 — 4y
0
I understand now, thank you WizardEpidemic 11 — 4y

Answer this question