Health bar problem

  1. What do you want to achieve? Keep it simple and clear!

A working health bar

  1. What is the issue? Include screenshots / videos if possible!

The health bar is not working properly
here is the health bar while my health is at 100
RobloxScreenShot20210911_100300010 (2)
and here it is when my health is at 1
RobloxScreenShot20210911_100304997 (2)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I try to change numbers in the script but still won’t work

here is the script

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health,false) 

--Variables
local player = game.Players.LocalPlayer
local char = player.Character
local gui = script.Parent
local frame = gui.Frame
local bar = frame.Frame

while wait() do
	-- Update bar
	bar.Size = UDim2.new(0.418,(char:WaitForChild("Humanoid").Health / char:WaitForChild("Humanoid").MaxHealth * 200),1*0.647,0)
end
1 Like

The UDim2 | Roblox Creator Documentation Property includes a (see edit) type format and it’ll change with the screen size you are playing on.
You need to figure out how to get the green Health bar’s percentage to display as a percentage of your white background.

Edit: sorry, it’s late and I completely botched my explanation of the UDim2 Constructor…

Why’s the MaxHealth getting multiplied by 200? Shouldn’t you be using the Scale and not the Offset for something like this?

The constructor for UDim2 is like this:

UDim2.new(ScaleX, OffsetX, ScaleY, OffsetY)

Keep in mind that Scale is a number from 0 to 1 in the UI object’s parent’s screen space, and that Offset is in pixels. For something like this, I would personally use Scale and not Offset.

2 Likes

You are giving the Bar Size a X Scale at 0.418. This mean it will always being Half. So you can fix this by using the Script below

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health,false) 

--Variables
local player = game.Players.LocalPlayer
local char = player.Character
local gui = script.Parent
local frame = gui.Frame
local bar = frame.Frame

while wait() do
	-- Update bar
	bar.Size = UDim2.new((char:WaitForChild("Humanoid").Health / char:WaitForChild("Humanoid").MaxHealth), 0,1*0.647,0)
end
1 Like