I even printed out the player name and double checked it in the workspace its the same!! and the output doesnt show any errors
game.Players.PlayerAdded:connect(function(player) print(player.Name) player:WaitForChild("Humanoid") if player:FindFirstChild("Humanoid") == true then print("Humanoid found!") end end)
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) --When a player joins print(player.Name) --Print the player's name player.CharacterAdded:Connect(function(character) --When the character loads if character:WaitForChild("Humanoid") then --If the humanoid exists inside of the character then proceed print("Humanoid found!") --Print that the humanoid has been found end end) end)
Your error on 4 line. Try this.
Line 3 useless, and humanoid belongs player.Character not player
game:GetService("Players").PlayerAdded:connect(function(player) print(player.Name) if player.Character:WaitForChild("Humanoid") then print("Humanoid found!") end end)