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

Why does the character variable get nil'd ingame?

Inside a LocalScript:

ply=game.Players.LocalPlayer
char=ply.Character
hum=char.Humanoid

I have also tried:

ply=game.Players.LocalPlayer
char=ply:WaitForChild('Character')
hum=char:WaitForChild('Humanoid')

Errors in-game:

attempt to index local 'char', a nil value

1 comment

0

poke (look below)

1 answer

✓ Accepted answer

You'll have to do

local char = ply.Character or ply.CharacterAdded:wait()

That last one will make the script yield till the characterAdded event is fired, and give the character as return instance.

3 comments

0

Thanks

0

Might I add, what do you use to define humanoid after that?

0

Theres no function for HumanoidAdded, you can use -----char:WaitForChild("Humanoid")------ instead.

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