#Healthbar Help

1 messages · Page 1 of 1 (latest)

errant apex
#

So... I can't make a health bar for this UI as every time I try to do, when I spawn, it protrudes out of the gui and doesn't event update. the local script is currently empty as i erased it ;-;

boreal riverBOT
#

studio** You are now Level 1! **studio

glass silo
#

check when the health of the character changes and just set the bar's size to Health/MaxHealth,0,1,0

karmic kernel
#

btw beautiful UI you got there

ember silo
#
local HPPercent=math.round(hum.Health/100)

TS:Create(bar, TweenInfo.new(0.05, Enum.EasingStyle.Quad, Enum.EasingStyle.In), {Size=Udim2.fromScale(HPPercent, 1)}):Play()

-- put this inside a while loop or run service
#

also state the humanoid

errant apex
#

here is the script btw:

local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid")

local HealthBar = script.Parent

local function updateHealth()
    local size = math.clamp(humanoid.Health / humanoid.MaxHealth, 0, 1)
    HealthBar.Size = UDim2.new(size, 0, 1, 0)
    script.Parent.Parent.Percentage.Text = tostring(math.floor(size * 100)).."%"
end

updateHealth()

humanoid:GetPropertyChangedSignal("Health"):Connect(updateHealth)
humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(updateHealth)```
#

got from a tutorial as i have no absolute scripting knowledge

karmic kernel
#

easy fix

#

HealthBar.Size = UDim2.new(size, 0, 1, 0)

#

here you put size in scale size right?

#

try to make it start with the size that your bar currently is

#

convert it to scale if possible

#

or else it'll be too big

karmic kernel
# errant apex sorry for the insanely late reply

you can also try to wrap the bar inside a container frame and only change the X.Scale part of the size. Make sure the bar’s AnchorPoint is set to (0, 0.5) and its Position to (0, 0.5, 0) so it scales from left to right correctly.

boreal riverBOT
#

studio** You are now Level 7! **studio

karmic kernel
#

changing the Y to 1

#

is pretty much telling it to go HUGE for 0 reason

#

'cause Y = height and X = width

errant apex
#

ah alr

#

ill try

#

:3

errant apex
#

NEW PROBLEM: IT AINT UPDATING

ember silo
#

it doesnt update bc it doesnt rlly affect anyways

#

anything

#

also maybe just do :Connect(function()
end)

#

and see what happens

#

also why maxhealth?

#

i just do it in a while true loop

#

or run service

#

instead of that

karmic kernel
# errant apex AH

uh add some print messages and see what works and what doesn't using simple debugging

karmic kernel
#

so doing a while true loop or stuff like that not only would it not let him do anything else in the same code

#

but it would look worse

ember silo