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

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

Asked by 5 years ago

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

Log in to vote
2
Answered by
popeeyy 493 Moderation Voter
5 years ago

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)
0
still Humanoid is not a valid member of Model themandes77 -1 — 5y
2
Then the person is dead or you have a script deleting it. popeeyy 493 — 5y
Ad

Answer this question