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

"Humanoid is not a valid member of Player" Error?

Asked by 4 years ago

I'm pretty unsure why I've been getting this error, I even printed it out and it returned Humanoid, so why am I getting this error?

game.Players.LocalPlayer.Character:WaitForChild("RightHand").Touched:Connect(function(hit)
    if playAnim.IsPlaying then
        print(hit.Parent:FindFirstChild("Humanoid"))
        if hit.Parent:FindFirstChild("Humanoid") and not debounce and not beenDamaged and hit.Parent ~= player.Humanoid then
            if player.Character.Humanoid.Health > 0 then
                beenDamaged = true
                replicatedStorage:WaitForChild("Punch"):FireServer(hit.Parent.Humanoid)
            end
        end
    end
end)

1 answer

Log in to vote
1
Answered by 4 years ago

When I first started learning Lua with Roblox, I did this all the time. Player refers to the actual player, while its child "Character" refers to the actual model in the Workspace. Because Humanoid is a child of the actual Character model, you cannot index it from "Player". So, to fix this, you would just change line 04 into: if hit.Parent:FindFirstChild("Humanoid") and not debounce and not beenDamaged and hit.Parent ~= player.Character then

The error message "Humanoid is not a valid member of Player" simply says "An object called Humanoid doesn't exist inside the Player" in more obvious English. Hope this answer helped :)

0
Thanks! baba7860 7 — 4y
Ad

Answer this question