#HealthBar not working
1 messages · Page 1 of 1 (latest)
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Healthbar = Player.PlayerGui.StatsBar.HealthFrame
local function UpdateHealthbar()
local health = math.clamp(Humanoid.Health / Humanoid.MaxHealth, 0, 1)
Healthbar.Size = UDim2.fromScale(400*health, 30)
end
UpdateHealthbar()
Humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHealthbar)
Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(UpdateHealthbar)
This is how it looks when I join the game
This is how it supposed to look normally
in UI scale is determined by it's parent. Scale 1 means that the Ui element is the same size as it's parent. You're changing it to 400*(val between 0 and 1) * 30. If it's set up correctly, then you should just be able to change it to fromScale(health, 1)
(but your healthbar not being parented to the frame, does tell it probably isn't (should've looked at this sooner), either set it up so they're parented to eachother, or just try to set them up in the exact same way, and refactor the previous formula with the default scales of the healthbar (scale, not offset)
I also changed the variable Healthbar to match the frame
Use canvas group
To make health bars and other bars
May I ask what that is? I haven't heard of it
It's a ui element
ah, I read about it and it's amazing! Thank you