Hi so I’m making a custom health bar GUI and the way it works is there’s a full health bar imagelabel and an empty health bar imagelabel inside a frame with clipsdecendants (the frame is inside the empty health bar imagelabel) on and every time you take damage the frame clips the full health imagelabel making the bar go down. It only crops the full health imagelabel when it’s on offset and not scale, so it doesn’t scale the full health bar to all platforms.
How can I make it so the frame crops the full health bar but make it scale size and position to all platforms?
Here is an outline of what you potentially may want to do
local player = game.Players.LocalPlayer -- Get the local player
local character = player.Character or player.CharacterAdded:Wait()
-- Get the character, if it is not already a created it will wait for it's creation through the CharacterAdded function
local humanoid = character:WaitForChild('Humanoid') -- Get the humanoid
humanoid.Changed:Connect(function()
-- Create your code that changes the health bar
end)
You will want to use their health divided by their max health in order to determine how far the bar should be
I’m not the greatest at explaining, but I’ll try.
To decrease the size you would want to link the size of the GUI to the max health of the player. How would you do that? Well you can get the original size of the GUI with something as simple as local originalsize = script.Parent.wherever it is.Size, and then multiplying it by the (health/max health), so the GUI gets to the correct size(user tween service if you want it to be smooth)
You would want to use the :GetPropertyChangedSignal for the health of the user every single time the user loses hp(Humanoid:GetPropertyChangedSignal(“Value):Connect(function()) to pick up the change in the hp of the user.
What explained goes for losing health, but what about gaining health? Well you can use variables in the script to pick up the “original” hp of the player, and compare it to the property changed signal hp of the player. Make an if statement for that, and add the hp!
Ideally you should separate the images/and make the green line just a rectangle ImageLabel and change the size of it dynamically as mentioned above.
In may case I made it out of 2 empty ImageLabels. They were just a background color. I set the todo bar as 0.75 transparent (just as a guide for the user to know where it will go). And then set the done line as 0% transparency.