Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Humanoid is not a valid member of Backpack error?

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)

3 comments

0

thats because humanoid is in their character...?

0

just add .Parent.Character before .Humanoid

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.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.