Whenever i try to access the local player i always gets nil as an error but idk why
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