How could I script a rolling health gui?

Example:
Rolling health bar

I was thinking to tween it, but I’m not sure how to tween that…

GuiObject:TweenPosition This will explain, how to move gui objects such as frames button.

On top of this, I would make each number its own frame and change its size downward. Make sure to revert the tween afterward and hide it.

2 Likes

I would use 1 textLabel per digit as a background that displays the hp, and only 1 textLabel that I call the roller… that rolls down. This is just an outline type code that I spent 5 minutes on, but heres an idea:

-- damage is the amount of damage taken
function updateHP(damage)
    local hpFrames = folderLocation
    local roller = frameLocation
    for frame = 1, damage do
        local first = hpFrames:FindFirstChild("first") -- first degit
        local second = hpFrames:FindFirstChild("second") -- second degit (tenth)
        if first:GetAttribute("HP") > 0 then
            local roll = tweenService:Create(roller, info, {Position = first.Position})
            roller.Text = first:GetAttribute("HP") - 1
            roll:Play()
            roll.Completed:Wait()
            first.Text = first:GetAttribute("HP") - 1
            first:SetAttribute("HP", first:GetAttribute("HP") - 1)
            roller.Position = first.Position+UDim2.new(0,0,-1,0)
        elseif second:GetAttribute("HP") > 0 then
            local roll1 = tweenService:Create(roller, info, {Position = first.Position})
            local roll2 = tweenService:Create(roller, info, {Position = second.Position})
            roller.Text = 9
            roll1:Play()
            roll1.Completed:Wait()
            first.Text = 9
            first:SetAttribute("HP", 9)
            roller.Position = second.Position+UDim2.new(0,0,-1,0)
            roller.Text = second:GetAttribute("HP") - 1
            roll2:Play()
            roll2.Completed:Wait()
            second.Text = second:GetAttribute("HP") - 1
            second:SetAttribute("HP", second:GetAttribute("HP") - 1)
            roller.Position = first.Position+UDim2.new(0,0,-1,0)
        else
            print("You are dead...")
            break
        end
    end
end)
1 Like

I’m a little confused but…

So if I read what you wrote correctly, there are two text labels side by side and then this local script can be located in the gui with the text labels. And then the first lable will change with the hp and then I get a bit lost…

Could you possibly explain the script a bit more or maybe add a video where I can visualize it? That would be great…

1 Like

Here is a video of the code in action:

Here is the experience where you can look at the completed code and mess around with:
HpRollingPlace.rbxl (39.6 KB)

2 Likes

Thanks!