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

attempt to index global 'Player' a nil value?

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?

3 comments

1

We need to have the whole script to see what lines reference players and or othererrors

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.

0

Okay ill give the whole script,i usually dont because people would steal my creations,anyways.

3 answers

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.

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.

1 comment

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)

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