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

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

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

✓ Accepted answer
wait()
player = game.Players.LocalPlayer
character = workspace:FindFirstChild(player.Name)
while character.Humanoid.Health > 0 do

3 comments

0

That should fix it!

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

0

You must wait first because it takes a secound to load the character, you are pretty much defining it before it loads

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