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

Output keeps saying "Humanoid is not valid member of Model"?

Asked by 7 years ago

The output error redirects to line 2. Here is the following code:

player = game.Players.LocalPlayer
playerHumanoid = player.Character.Humanoid

function update()
    local hp = playerHumanoid.Health
    local maxhp = playerHumanoid.MaxHealth

    local health = hp / maxhp

    if health <= 0 then
        script.Parent.Bar:TweenSize(UDim2.new(0.01, 0, 1, 0), "Out", "Quad", 0.2)
        script.Parent.TextLabel.Text = "0/"..maxhp.." Health"
    end

    script.Parent.Bar:TweenSize(UDim2.new(health, 0, 1, 0), "Out", "Quad", 0.2)
    script.Parent.TextLabel.Text = math.floor(hp+0.5).."/"..maxhp.." Health"

end

update()

playerHumanoid.HealthChanged:connect(update)

I have a feeling that it has to do with the lack of code that checks if the model has or doesn't have the humanoid object, but usually it only has to do with buttons that are touched (if I am correct).

0
I would like to add that this script is for a health bar. User#17080 0 — 7y
1
try :WaitForChild('Humanoid') noposts 75 — 7y
0
Try FindFirstChild("Humanoid") or WaitForChild("Humanoid") Alec77733 2 — 7y

2 answers

Log in to vote
0
Answered by
rnizam 1
7 years ago

You're probably making it run too early. Try waiting a second or so for the Humanoid to load.

Ad
Log in to vote
0
Answered by 7 years ago

Try FindFirstChild("Humanoid") or WaitForChild("Humanoid")

0
I tried your suggestion and it still outputs the same error. User#17080 0 — 7y

Answer this question