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

How do i fix this error in my custom health bar script??

local plr = game.Players.LocalPlayer.Character while true do script.Parent:TweenSize(UDim2.new(plr.Humanoid.Health/plr.Humanoid.MaxHealth, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1) wait(0.1) end

and the error it gives is

Humanoid is not a valid member of Model

1 answer

✓ Accepted answer

You should use WaitForChild to wait for the Humanoid. You should also use .Changed on the humanoid to check when the health changes, not loop, it will result in higher performance. Here is what I would do:

local plr = game.Players.LocalPlayer.Character
local human = plr:WaitForChild('Humanoid')
human.Changed:connect(function()
	script.Parent:TweenSize(UDim2.new(human.Health/human.MaxHealth, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.1) 
end)

2 comments

0

still Humanoid is not a valid member of Model

2

Then the person is dead or you have a script deleting it.

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