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

"attempt to index local 'player' (a nil value)"?

Asked by 5 years ago
Edited 5 years ago

So I'm having an issue right now creating a tool. This message popped out when I played in online mode. The error comes from line 3. Do you know how to fix it?

Btw, it is a localscript


local t = script.Parent local player = game.Players.LocalPlayer.Character local torso = player:WaitForChild("Torso")
0
probably you should wait for the character to load Rare_tendo 3000 — 5y
0
There's a WaitForChild at the third line, so I don't think thats the issue masterjosue1998 116 — 5y
0
but it uses the variable to get the torso though User#23365 30 — 5y
0
It is the issue. Define the player in one line (using just local player = game.Players.LocalPlayer) and then the character in the next (using player.Character or player.CharacterAdded:Wait()). This way, the script will wait for the character to load. lunatic5 409 — 5y
View all comments (2 more)
0
Or, you can actually just do it in one line like so: local player = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait(). I would opt for the first option though as the player variable will most likely come in handy later and that way you can have a variable for both the player and the character. lunatic5 409 — 5y
0
My tool works now. Thanks alot guys masterjosue1998 116 — 5y

Answer this question