Hello everyone, I’ve made some modifications to a Health Bar UI to turn it vertical, however the frame is subtracting upwards instead of downwards, which is what I’m trying to achieve.
I have tried different UDim2.new values, changing the frame’s anchor points and SizeConstraint, looked online for possible solutions, but no luck with my current (or rather lack thereof) knowledge of scripting. (To be honest I have been using ChatGPT to try and write scripts, which has been both a blessing and a curse, but that’s another topic).
A few details on the hierarchy and properties:
In StarterGUI:
Hierarchy
“Bar” Properties
The LocalScript itself (Credit to AdvancedDrone for creating it):
LocalScript
local StarterGui = game:GetService('StarterGui')
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
local Player = game.Players.LocalPlayer
local Character
repeat Character = Player.Character wait() until Character ~= nil
function GetTools(Model)
local Num = 0
for _, v in pairs(Model:GetChildren()) do
if v:IsA("Tool") or v:IsA("HopperBin") then
Num = Num + 1
end
end
return Num
end
function Transformar(R, G, B)
return Color3.new(R/255, G/255, B/255)
end
function Actualizar()
local Tools = 0
Tools = Tools + GetTools(Player.Backpack) + GetTools(Player.Character)
if Tools == 0 then
script.Parent:WaitForChild("HPBackground").Position = UDim2.new(0, 10,1, -52)
else
script.Parent:WaitForChild("HPBackground").Position = UDim2.new(0, 10,1, -52)
end
end
delay(0, function()
Player.Character.Humanoid.Changed:connect(function()
if Player.Character.Humanoid.Health == math.huge then
-- God mode: Set the health bar to full height
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(51, 255, 51)
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").Size = UDim2.new(1, 0, 1, 0)
script.Parent:WaitForChild("HPBackground"):WaitForChild("DamageBar").Size = UDim2.new(1, 0, 1, 0)
else
-- Calculate health percentage
local Calculo = Player.Character:WaitForChild("Humanoid").Health / Player.Character:WaitForChild("Humanoid").MaxHealth
-- Update the health bar's height and animate it
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").Size = UDim2.new(1, 0, Calculo, 0)
script.Parent:WaitForChild("HPBackground"):WaitForChild("DamageBar"):TweenSize(UDim2.new(1, 0, Calculo, 0), "In", "Quad", 0.25, true)
-- Set the health bar's background color
local Var = Player.Character:WaitForChild("Humanoid").MaxHealth / 4
if Player.Character:WaitForChild("Humanoid").Health <= Var then
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 51, 51)
elseif Player.Character:WaitForChild("Humanoid").Health <= Var * 2 then
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 170, 0)
elseif Player.Character:WaitForChild("Humanoid").Health <= Var * 3 then
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(255, 255, 51)
else
script.Parent:WaitForChild("HPBackground"):WaitForChild("Bar").BackgroundColor3 = Transformar(51, 255, 51)
end
end
end)
end)
Any suggestions would help immensely.