I figured out that I just had to check the sizes once not every time the health changes
I just put --sizes outside of HealthChanged event
02 | local plr = game.Players.LocalPlayer |
03 | local char = plr.Character or plr.CharacterAdded:Wait() |
04 | local frame = script.Parent |
07 | local nextLvl = frame.NextLvl |
08 | local hpDisplay = frame.HPDisplay |
09 | local stamina = frame.Stamina |
10 | local xpDisplay = frame.XPDisplay |
11 | local hum = char:WaitForChild( 'Humanoid' ) |
14 | local curHp = hum.Health |
15 | local curMaxHp = hum.MaxHealth |
16 | hp.Text = 'Hp: ' .. tostring (curHp).. '/' .. tostring (curMaxHp) |
19 | local xScale = hpDisplay.Size.X.Scale |
20 | local xOffset = hpDisplay.Size.X.Offset |
21 | local yScale = hpDisplay.Size.Y.Scale |
22 | local yOffset = hpDisplay.Size.Y.Offset |
25 | char.Humanoid.HealthChanged:connect( function () |
26 | local curHealth = hum.Health |
27 | local curMaxHealth = hum.MaxHealth |
29 | local percentage = curHealth/curMaxHealth |
30 | local newXOffset = percentage*xOffset |
33 | hpDisplay:TweenSize(UDim 2. new(xScale,newXOffset,yScale,yOffset), 'Out' , 'Quad' ,. 5 , false , nil ) |
34 | hp.Text = 'Hp: ' .. tostring (math.floor(curHealth + . 5 )).. '/' .. tostring (curMaxHealth) |