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

Can't get "Humanoid" from a player?

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

2 comments

0

You haven't defined Character and the player

0

like this? "game.Players.LocalPlayer.Character.Humanoid"? that doesnt work either

1 answer

##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)

2 comments

0

You can use just do player.Character or player.CharacterAdded:Wait()

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.

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