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 Backpack error?

Asked by 6 years ago

I am trying to make this weapon that heals the player when their HP hits or is below a certain number, but the thing is, I keep getting an error. The error states that Humanoid is not a valid member of backpack. I've tried doing something like this before, but it worked perfectly. It is a normal script, and it is not a local script, although I have tried to convert it to local, and it still didn't work. What am I doing wrong?

script.Parent.Parent.Humanoid.HealthChanged:connect(function(hp)

if hp <= 0.01 then
print("Heal the player!")
script.Parent.Parent.Humanoid.Health = 10
wait(0.1)
end

end)
0
thats because humanoid is in their character...? abnotaddable 920 — 6y
0
just add .Parent.Character before .Humanoid abnotaddable 920 — 6y
0
Thank you for the help, however, it only works for line 1. I tried it in line 5, and Output stated that "Character is not a valid member of Workspace". I tried removing a few of the parents, no luck. SpiritualRazor 2 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Not for sure where you are getting at, but this may help:

local wfc = game.WaitForChild
local player = game.Players.LocalPlayer
local phum = wfc(player.Character,"Humanoid")

phum.Changed:connect(function() --detection of health change
    if phum.Health == 0 or phum.Health < 1 then
        phum.Health = 10
    end
end)

This script can really work anywhere you put it, so I hope this helps.

Ad

Answer this question