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

Why does the character variable get nil'd ingame?

Asked by 7 years ago

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

0
poke (look below) RubenKan 3615 — 7y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago

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.

0
Thanks MexicanGod13 6 — 7y
0
Might I add, what do you use to define humanoid after that? MexicanGod13 6 — 7y
0
Theres no function for HumanoidAdded, you can use -----char:WaitForChild("Humanoid")------ instead. RubenKan 3615 — 7y
Ad

Answer this question