#How would I make a Hp/Stamina or Energy bar if the bar is made from 2 images?

1 messages · Page 1 of 1 (latest)

arctic quarry
#

It works but the first frames(the ones with start) don't decrease at all,while the last frames(the ones with end) decrease slowly until the Player's HP = 0```
local Player = game:GetService("Players").LocalPlayer
local TotalFrame = script.Parent

local TFHP = TotalFrame.HealthBar

local HPBarClippingEnd = TFHP.BottomEndImage.TopEnd
local HPBarTopEnd = HPBarClippingEnd.TopEndImage

local HPBarClippingStart = TFHP.BottomStartImage.TopStart
local HPBarTopStart = HPBarClippingStart.TopStartImage

local HPBarChildToChose = 2

function resizeCustomLoadingBar(SizeRatio, Clipping, Top)

Clipping.Size = UDim2.new(SizeRatio, Clipping.Size.X.Offset, Clipping.Size.Y.Scale, Clipping.Size.Y.Offset)
Top.Size = UDim2.new((SizeRatio > 0 and 1 / SizeRatio) or 0, Top.Size.X.Offset, Top.Size.Y.Scale, Top.Size.Y.Offset) -- Extra check in place just to avoid doing 1 / 0 (which is undefined)

end

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

Humanoid.HealthChanged:Connect(function(NewHealth)
if HPBarClippingStart.Size == UDim2.new(1,0,1,0) then
HPBarChildToChose = 2
else
HPBarChildToChose = 1
end
if HPBarChildToChose == 1 then
local MaxHealth = Humanoid.MaxHealth
local HealthRatio = NewHealth / MaxHealth -- the ratio of the bar to be set

    local HPBarClipping = HPBarClippingStart
    local HPBarTop = HPBarTopStart
    resizeCustomLoadingBar(HealthRatio, HPBarClipping, HPBarTop)
else
    local MaxHealth = Humanoid.MaxHealth
    local HealthRatio = NewHealth / MaxHealth -- the ratio of the bar to be set

    local HPBarClipping = HPBarClippingEnd
    local HPBarTop = HPBarTopEnd
    resizeCustomLoadingBar(HealthRatio, HPBarClipping, HPBarTop)
end

end)

craggy heart
#

u could make a size tween with the ui or have an invisible gui off screen that the health bar tweens towards to look like health drainage