so in the video you see how it currently works and how the script is, but i want that “Bar” to goes in the bottom if the health is getting lower from the max. so i basicly want that thing but upside down.
thats the script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum
if character then
hum = character:WaitForChild("Humanoid")
end
local clippingframe = script.Parent.Frame
local healthbartop = clippingframe.healthbar
local sizeratio = script.Parent.UIAspectRatioConstraint
hum.HealthChanged:Connect(function()
local healthratio = hum.Health / hum.MaxHealth
clippingframe:TweenSize(UDim2.new(clippingframe.Size.X.Scale, clippingframe.Size.X.Offset, healthratio, clippingframe.Size.Y.Offset), "Out", "Linear", 0.1)
healthbartop:TweenSize(UDim2.new(healthbartop.Size.X.Scale, healthbartop.Size.X.Offset, (healthratio > 0 and 1 / healthratio) or 0, healthbartop.Size.Y.Offset), "Out", "Linear", 0.1)
end)
so if the Health is lower then MaxHealth then i want the bar to goes down but if the Health is getting regenerated i want it to goes up (with clipping)
thats btw how the gui currently looks in the Explorer
The “Frame” is the clipping frame
and the Healthbar is the “Image” i want to clip that it looks clean
I would probably add another TweenPosition to move the clippingframe down so its bottom is touching the lower edge of the healthholder. So this is probably what I’ll do:
this is the new script and now its working fine. HP low the red bar is going down and if the hp is going from low to high again the hp bar is going higher.
Here is the script:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum
local currenthealth
if character then
hum = character:WaitForChild("Humanoid")
currenthealth = hum.Health
end
local clipper = script.Parent.Clipper
local bar = clipper.Bar
hum.HealthChanged:Connect(function(newhealth)
if newhealth < currenthealth then
currenthealth = newhealth
local ratio = hum.Health / hum.MaxHealth
clipper:TweenPosition(UDim2.new(clipper.Position.X.Scale, clipper.Position.X.Offset, 0.5 + ratio, clipper.Position.Y.Offset), "In", "Linear", 0)
bar:TweenPosition(UDim2.new(bar.Position.X.Scale, bar.Position.X.Offset, 0.5 - ratio, bar.Position.Y.Offset), "In", "Linear", 0)
elseif newhealth > currenthealth then
currenthealth = newhealth
local ratio = hum.Health / hum.MaxHealth
clipper:TweenPosition(UDim2.new(clipper.Position.X.Scale, clipper.Position.X.Offset, 1.5 - ratio, clipper.Position.Y.Offset), "In", "Linear", 0)
bar:TweenPosition(UDim2.new(bar.Position.X.Scale, bar.Position.X.Offset, -0.5 + ratio, bar.Position.Y.Offset), "In", "Linear", 0)
end
end)