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

attempt to index global 'Player' a nil value?

Asked by 8 years ago
Edited 8 years ago

So what im trying to do is basiclly a fireball move. Not gonna give the whole script,but heres a line.

local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local Char = Player.Character

I tried on local script but it says that 'Char' is a nil value,Why? You probably see what im trying to do.

Basiclly its giving this error about local "Player" And its ruining the whole thing,it works on the studio but not here. Anyone know an answer?

1
We need to have the whole script to see what lines reference players and or othererrors DeveloperSolo 370 — 8y
0
Kristi, without the rest of the script we can't do anything to find an error. in the Output tab, it should give you something that looks like "Workspace.scriptParent.Script:40: Error Description" What does that say? that will give you which line the code is having the problem with, and would allow us to look into it more. Otherwise, maybe try creating that variable on playerAdded. areiydenfan00 115 — 8y
0
Okay ill give the whole script,i usually dont because people would steal my creations,anyways. kristibezatlliu1111 33 — 8y

3 answers

Log in to vote
1
Answered by 8 years ago

My guess is that you're trying to access the LocalPlayer from a server-side script. This means that in studio, where everything is local, LocalPlayer will always return Player1. However, in a game, LocalPlayer cannot be accessed unless it's from a LocalScript which is left somewhere inside the player.

Unfortunately, I can't really help you more unless I see more of the script, but I hope my suggestion will help you fix it.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Possible Problems

Since I don't see your full script, it could be either you are trying to access LocalPlayer in a server-sided script or you are trying to write LocalPlayer instead of reading it. There's a high possibility its the second problem, I'll give explanations to both of the problems below.

First problem answer

You can only access LocalPlayer through a Local Script. Trying to run it through a server-sided script(Regular script) will cause an error.

Second problem answer

If you are trying to get the player's name you should just put:

local Player = game.Players.LocalPlayer.Name

If this was helpful please give accept this answer.

0
Yes it works on a local script,but as you can see im trying to acces the player's character too,now it says Attemp to index local 'Char' (a nil value) kristibezatlliu1111 33 — 8y
Log in to vote
0
Answered by 8 years ago

LocalPlayer only works in a Local Script

Answer this question