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

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

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).

3 comments

0

I would like to add that this script is for a health bar.

1

try :WaitForChild('Humanoid')

0

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

2 answers

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

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

1 comment

0

I tried your suggestion and it still outputs the same error.

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