Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my Background Transperancy go higher as my Health go lower?

Asked by 2 years ago

Hello I am trying to make GUI that becomes more and more transparent as your Health goes lower does anybody have any idea like how it should be?

local humanoid = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid")
local gui = script.Parent


    humanoid.HealthChanged:Connect(function()
        local percent = humanoid.Health/humanoid.MaxHealth
    gui.BackgroundTransparency = percent
    end)

Keep in mind this script makes the transperancy goes higher as the health goes higher and when you're at 100% Health, it's just full transparent when I want it to be 0% Transparent when it's 100%

1 answer

Log in to vote
1
Answered by
Y_VRN 246 Moderation Voter
2 years ago
Edited 2 years ago

Change line 7 to this:

gui.BackgroundTransparency = 1 - percent

The "percent" variable starts as 1 as the health is in max. When the player gets 25 damage points (assuming the max health is 100), then the "percent" variable becomes 0.75. Subtracting 0.75 to one gets us 0.25, increasing the transparency.

(edit 1: quick fix about my math)

Ad

Answer this question