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

I can't access LocalPlayer in a normal sript?

Asked by 9 years ago

This..... just doesn't work. D: The debugger tells me that my 'player' variable is nil. I dunno what to do; can someone help please?

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

1 answer

Log in to vote
2
Answered by 9 years ago

You can't access LocalPlayer from ServerScripts. If the script is inside the StarerGui, or StarterPack, then just

local player = script.Parent.Parent

This will get the scripts 'Parent' which is the StarterGui, or in this case the PlayerGui, and it again gets the parent of that, which is the player itself.

NinjoOnline

0
Thanks. I forgot about that. :D imperialstar 110 — 9y
0
Note that this won't work with FilteringEnabled (Scripts don't run in playergui), and FilteringEnabled IS recommended BlueTaslem 18071 — 9y
Ad

Answer this question