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

LocalPlayer - does it exist?

Asked by 5 years ago
Edited 5 years ago

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...

0
LocalPlayer can only be used in a LocalScript JayzYeah32 62 — 5y
0
I already tried it, but the error message is the same... LordTechet 53 — 5y
0
print(game.Players.LocalPlayer) User#24403 69 — 5y
0
it may because the script runs faster than the games does XviperIink 428 — 5y
View all comments (4 more)
0
That is wrong. LocalPlayer will never be nil on the client side. OP just being big dum dum User#24403 69 — 5y
0
Using that printing code given by Incapaxx I get 'Nil' LordTechet 53 — 5y
0
On the server side, yes. Client side, no. User#24403 69 — 5y
0
So, how to fix that? LordTechet 53 — 5y

1 answer

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
5 years ago

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.

Ad

Answer this question