Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make this health bar decrease it's size as the value goes down of a number value?

Asked by 7 years ago

I'm making a card game and I'm trying to add a health to the card. Here's the script;

local healthbar = script.Parent.Parent:WaitForChild("HealthBar")
local currenthealth = script.Parent:WaitForChild("CurrentHealth")
local maxhealth = script.Parent:WaitForChild("MaxHealth")
local cardlevel = script.Parent.Parent.Parent.CardLevel:WaitForChild("CardLv")
local cardhealthtext = script.Parent

while true do
    wait(0.1)
    cardhealthtext.Text = currenthealth.Value.." / "..maxhealth.Value
    if cardlevel.Value > 1 then
        maxhealth.Value = maxhealth.Value + (cardlevel.Value * 2)
        local Health = currenthealth.Value / maxhealth.Value
        healthbar.Size = UDim2.new(Health, 0, 1, 0)
    end 
end

There was no errors but the health bar won't change sizes, Please help

0
Where is the script located? nforeman 15 — 7y
0
The scale property is your best friend AnswerXOX 4 — 7y
0
Script located in side a ScreenGui BlackOrange3343 2676 — 7y
0
script looks good to me. cabbler 1942 — 7y
0
Make sure cardlevel is greater than 1. Disillusions 61 — 7y

1 answer

Log in to vote
-1
Answered by 7 years ago

Multiply the percentage by the size of the health bar at max

local Health = currenthealth.Value / maxhealth.Value
healthbar.Size = UDim2.new(Health * maximumSize, 0, 1, 0)
Ad

Answer this question