Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

5 comments

0

Where is the script located?

0

The scale property is your best friend

0

Script located in side a ScreenGui

0

script looks good to me.

0

Make sure cardlevel is greater than 1.

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.