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