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

Can't get "Humanoid" from a player?

Asked by 3 years ago

I get this error everytime :

Players.ItsAntonio_xD.PlayerScripts.LocalScript:1: attempt to index nil with 'WaitForChild'

The code:

local humanoid = script.Parent.Parent.Character:WaitForChild("Humanoid")
humanoid.Jumping:Connect(function()
    print("hey")
end)

And if I remove the "WaitForChild" I get the same error

The script is in StarterPlayerScripts, and it is a local script too

0
You haven't defined Character and the player JesseSong 3916 — 3y
0
like this? "game.Players.LocalPlayer.Character.Humanoid"? that doesnt work either antvvnio 40 — 3y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Corrected Script:

wait() --  add some kind of wait so that you'll have enough time for the player to load, otherwise you'll receive an error
local player = game.Players.LocalPlayer.Character
local humanoid = player.Humanoid
humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
    print("hey")
end)
0
You can use just do player.Character or player.CharacterAdded:Wait() Dovydas1118 1495 — 3y
0
That will function when a player's character spawns or respawns, it doesn't matter which you use, and you don't need it for this task. JesseSong 3916 — 3y
Ad

Answer this question