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

Why do i get local player as nil?

Asked by 5 years ago

Whenever i try to access the local player i always gets nil as an error but idk why

1 answer

Log in to vote
0
Answered by 5 years ago

You are probably trying to get the local player using a server script, which of course will not work.

You can get the LocalPlayer by using a LocalScript and placing it under client-"only" places like StarterGui (Called "PlayerGui" in-game).

local Players = game:GetService("Players");
local LocalPlayer = Players.LocalPlayer;

print("The local player's name is:", LocalPlayer.Name);
--> The local player's name is: WhereAreTheLights
Ad

Answer this question