Hey guys, so I was creating a custom health bar over the player's head using BillboardGui and it works fine except when the size of the bar falls to ~37% of its original size it just vanishes! If you could help me, that'd be awesome. Here's the script I'm using:
local gui = Instance.new('BillboardGui', script) gui.Size = UDim2.new(1,0,1,0) gui.StudsOffset = Vector3.new(0,3,0) local l = Instance.new('Frame', gui) l.Position = UDim2.new(-1.5,0,0,0) l.Size = UDim2.new(4,0,.5,0) l.BorderSizePixel = 0 l.BackgroundTransparency = 1 local h = Instance.new('Frame', l) h.Size = UDim2.new(1,0,1,0) h.BorderSizePixel = 0 h.BackgroundTransparency = .6 h.ZIndex = 2 h.BackgroundColor3 = Color3.new(0,.8,.15) local t = Instance.new('TextLabel', h) t.Size = UDim2.new(1,0,1,0) t.TextColor3 = Color3.new(1,1,1) t.ZIndex = 3 t.BackgroundTransparency = 1 t.Text = '100%' game.Players.PlayerAdded:connect(function(plr) plr.CharacterAdded:connect(function(chr) if chr:findFirstChild("Head") then local humanoid = chr:WaitForChild('Humanoid') local temp = gui:clone() temp.Parent = chr.Head humanoid.HealthChanged:connect(function(health) local healthPercentage = health / chr.Humanoid.MaxHealth temp.Frame.Frame:TweenSize(UDim2.new(healthPercentage,0,1,0),"Out","Bounce",0.7,true) temp.Frame.Frame.TextLabel.Text = (math.floor(healthPercentage * 100) .. "%") if health >= 70 then temp.Frame.Frame.BackgroundColor3 = Color3.new(0,.8,.15) else temp.Frame.Frame.BackgroundColor3 = Color3.new(.88,.72,0) wait() end end) end end) end)
Also an additional question, how would I make it so the bar also goes to red if the player's health falls below 30%? I can't do it without something going wrong.