Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LocalPlayer - does it exist?

So, I've done a few attempts of a script and I get that same error message all the time -

14:13:23.119 - Workspace.Grab.Script:2: attempt to index global 'player' (a nil value)

It doesn't matter if it's a LocalScript or a Script, or has a Local infront of the line.

player = game.Players.LocalPlayer
Character = player.Character

After many attempts of different combinations I started to doubt of the existence of LocalPlayer since Roblox has went through a few updates...

Here's what I did to see if LocalPlayer is found or not:

if game.Players.LocalPlayer then
print("LocalPlayer found!")
else if not game.Players.LocalPlayer then
	print("LocalPlayer not found!")
end
end

And I got "LocalPlayer not found!"

I also noticed that my scripts disappear from my character when I test my game...

8 comments

0

LocalPlayer can only be used in a LocalScript

0

I already tried it, but the error message is the same...

0

print(game.Players.LocalPlayer)

0

it may because the script runs faster than the games does

0

That is wrong. LocalPlayer will never be nil on the client side. OP just being big dum dum

0

Using that printing code given by Incapaxx I get 'Nil'

0

On the server side, yes. Client side, no.

0

So, how to fix that?

1 answer

First of all theres no need to see if localplayer is nil or not because it will never be nil if your getting it from the right place. You also need a local at the values and it needs to be a localscript to work. I did your if thing in a local script and it worked fine in studio. Also the scripts when you test the game because did a update so you have to click current: client to go the server and see server scripts. But because you said that its clearly not a localscript because it would show up anyways.

This discussion is preserved as it was. New answers, comments, and votes are closed.