Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.