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

Player says it's nil, Studio says it exists?

Asked by 8 years ago
Edited 8 years ago
Player = game.Players.LocalPlayer.Character
while Player.Humanoid.Health > 0 do

These are the lines that are giving me trouble; they're from a larger script, but the rest isnt relevant. Studio has no errors with the lines of code, but Player says this attempt to index "Player" (a nil value) I have many more errors in my other localscripts that do not occur in Studio. Does anybody have the solution for this? Thank you.

Edit: Player, as in ROBLOX Player. Studio, as in ROBLOX Studio. Don't get it confused with the variable, which is named Player.

1 answer

Log in to vote
1
Answered by
Mapyo30 10
8 years ago
Edited 8 years ago
wait()
player = game.Players.LocalPlayer
character = workspace:FindFirstChild(player.Name)
while character.Humanoid.Health > 0 do
0
That should fix it! Mapyo30 10 — 8y
0
Thank You! But why does game.Players.LocalPlayer.Character work in Studio but not in Roblox Player? It's even referenced on the Wiki ShiningWindow 127 — 8y
0
You must wait first because it takes a secound to load the character, you are pretty much defining it before it loads Mapyo30 10 — 8y
Ad

Answer this question