I'm making a custom health bar but its having trouble updating

ok, so im making a custom gui health bar and i have made it so it hides the normal health bar and instead whenever the health changes, so when you heal or take damage, it updates like the normal health bar since the new health bar looks disgusting.

Although on doing this using the GetPropertyChangedSignal() on the health bar when it takes damage it acts normal, but on healing it doesn’t, and it just shows blank. Here is the video of this happening:

And here is my code:

local StarterGUI = game:GetService("StarterGui")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local text = script.Parent

StarterGUI:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	print(humanoid.Health)
	if humanoid.Health ~= 100 then
		text.Text = "Health:  " ..tostring(humanoid.Health)
	else
		text.Text = "Health: 100"
	end
end)

I’m Unsure if this is the case although it says that GetPropertyChangedSignal() only updates for bools, ints and strings and looking at the print statements it clearly shows while healing it makes the health a float (a number with decimals) and i’m wondering if thats doing something but then the print statement is in the GetPropertyChangedSignal()? Im Quite Confused On Why This Is Happening

It’s likely because the text doesn’t fit in your UI from how long the number is, you can use TextScaled so that the text will automatically scale based on the length of the text, although you could also just round the health with math.round

1 Like

thanks, that worked. i was looking for a way to round up the decimals and i didn’t know this until now, thanks again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.