✓ Accepted answer
First of all, the Humanoid is located in the player's character, not the player itself. You must wait for the character to load, however, so you must use a CharacterAdded event:
player.CharacterAdded:Connect(function(character)
By all means, though, do not use WaitForChild on the character, as it is a property, and WaitForChild cannot be used on properties.
Also, connect is deprecated; use Connect instead. It is also unnecessary to use "== true" after FindFirstChild. You can simply use the following:
if example:FindFirstChild("example") then
However, if you'd like to check if FindFirstChild returns false, then you can use not.
Example:
if not example:FindFirstChild("example") then
Finally, I believe this link will be of help to you: https://www.robloxdev.com/articles/Writing-Clean-Code
Please indent your code. It makes it much more legible and comprehensible, therefore making it easier to fix or get help with.
Here is the final product:
game:GetService("Players").PlayerAdded:Connect(function(player)
print(player.Name)
player.CharacterAdded:Connect(function(character)
if character:WaitForChild("Humanoid") then
print("Humanoid found!")
end
end)
end)
4 comments
you could also instead use the CharacterAdded event connecting to a function
What i meant was to do Workspace:WaitForChild(plr.Name), not the character. I guess i wasnt specific enough.
What i meant was to do Workspace:WaitForChild(plr.Name), not the character. I guess i wasnt specific enough.
While that would work, it would be more efficient to use the built in event. And yes, EX, I somehow overlooked that. I'm going to update that now.