humanoid = game.Players.LocalPlayer.Character
humanoid.Humanoid.Changed:connect(function()
if humanoid.Humanoid.Health == 100 then
script.Parent.Frame.Size = UDim2.new(0, 500, 0, 20)
else if humanoid.Humanoid.Health <= 99 and humanoid.Humanoid.Health > 91 then
script.Parent.Frame.Size = UDim2.new(0, 450, 0, 20)
else if humanoid.Humanoid.Health <= 90 and humanoid.Humanoid.Health > 81 then
script.Parent.Frame.Size = UDim2.new(0, 400, 0, 20)
else if humanoid.Humanoid.Health <= 80 and humanoid.Humanoid.Health > 71 then
script.Parent.Frame.Size = UDim2.new(0, 350, 0, 20)
else if humanoid.Humanoid.Health <= 70 and humanoid.Humanoid.Health > 61 then
script.Parent.Frame.Size = UDim2.new(0, 300, 0, 20)
else if humanoid.Humanoid.Health <= 60 and humanoid.Humanoid.Health > 51 then
script.Parent.Frame.Size = UDim2.new(0, 250, 0, 20)
else if humanoid.Humanoid.Health <= 50 and humanoid.Humanoid.Health > 41 then
script.Parent.Frame.Size = UDim2.new(0, 200, 0, 20)
else if humanoid.Humanoid.Health <= 40 and humanoid.Humanoid.Health > 31 then
script.Parent.Frame.Size = UDim2.new(0, 150, 0, 20)
else if humanoid.Humanoid.Health <= 30 and humanoid.Humanoid.Health > 21 then
else if humanoid.Humanoid.Health <= 20 and humanoid.Humanoid.Health > 11 then
script.Parent.Frame.Size = UDim2.new(0, 50, 0, 20)
else if humanoid.Humanoid.Health <= 10 and humanoid.Humanoid.Health >= 1 then
script.Parent.Frame.Size = UDim2.new(0, 0, 0, 20)
else if humanoid.Humanoid.Health == 0 then
print("you ded")
end
end
end
end
end
end
end
end
end
end
end
end
end)
Making a healthbar, not the best solution, but it's just a first try test.
It works fine in studio, but not the actual game itself. It's inside a ScreenGui in StarterGui & isn't a local script.

2 comments
I recommend using Scale (the first & third parameters in UDIM2.new) property, as Offset works w/ pixels, while Scale supports separate platforms, such as computers, tablets, etc.
Good tip! I read about that after I already positioned all of my GUI elements by pixel. I plan on converting it all to scale soon, but haven't gotten around to it. Thanks for the reminder!