Its applying an offset to the Y position as seen in the code
local newFrameSize = UDim2.new(0, CurrentHealth * 3, 0, 8)
UDim2
uses four components being: XScale
, XOffset
, YScale
, and YOffset
Scale
is the percentage that the UI will take up according to what its parented to. Such as this health bar’s parent Frame
Offset
is based on pixels, which means that its size and position is based on your screen resolution.
YOffset
is applying a offset of 8
, meaning that it will move downwards 8
.
Based on the size, its using only the Offset
portion of the bar is the only thing being updated, meaning that will will always have a fixed sized based on how big the UI is, in order to fix, its going to need to be switched to Scale
.
I dont expect you to know how to adjust the UI properly (I have trouble sometimes) so here’s the finished result when switching the bar from Offset
to Scale
, and some updates to the hirearchy, and in order to script the bar accordingly, use what @BonesIsUseless reccommended:
--// Health/MaxHealth is the percentage that the health is that
-- when applied to XScale, it will cover based on the percentage given
-- (50% = 0.5) will cover 50% of the bar
--// The 1 on YScale is so the Height of the bar always covers the height
-- unless you are trying to add a second bar, dont mess with it.
--// 'Bar' is the outline of the healthbar, and or Back portion
-- its responsible for the sizing of the bar
--// 'Fill' is the thing you want to update, and will update
-- accordingly to the sizer of 'Bar'
If you use Offset
instead of Scale
, it will not adjust properly.
OverheadUI.rbxl (72.6 KB)
Also, tell your friend that instead of updating every second, he should update when the health of the player updates using Humanoid.HealthChanged
, this would much less expensive on the systems end.