How to get a GUI to lose transparency when a value is below a certain point

Hello! I’m a beginner scripter in need of help.
I am making a script where a GUI loses transparency when someone’s “air” (a value) is below a certain point/level.

The script does not work at all, but no errors show up inside of the console.

I didn’t look through anything yet, because I immediately wanted to go here for help.

Here is my script:

AirValue = game.Players.LocalPlayer.Character.Water.Air
Transparency = script.Parent.LowOxygenEffect.BackgroundTransparency

while true do
	if AirValue <= 35 then
		Transparency = AirValue * 2
		wait(0)
	elseif AirValue >= 35 then
		Transparency = 1
	end
end

If you are able to help, please do! ^-^

1 Like

Sadly you can’t reference properties that way. We can change the code a little to reference the LowOxygenEffect Object directly and change the property from there.

AirValue = game.Players.LocalPlayer.Character.Water.Air
TransparencyObj = script.Parent.LowOxygenEffect

while true do
	if AirValue <= 35 then
		TransparencyObj.BackgroundTransparency = AirValue * 2
		wait(0)
	elseif AirValue >= 35 then
		TransparencyObj.BackgroundTransparency = 1
	end
end
1 Like

try

AirValue = game.Players.LocalPlayer.Character.Water.Air
Transparency = script.Parent.LowOxygenEffect.BackgroundTransparency

while true do
	if AirValue.Value <= 35 then
		script.Parent.LowOxygenEffect.BackgroundTransparency = AirValue.Value * 2
		wait(0)
	elseif AirValue.Value >= 35 then
		script.Parent.LowOxygenEffect.BackgroundTransparency = 1
	end
end

I’ve just realized that I can’t use division in this way (I meant for it to be ‘/’, not ‘*’) because if the air was 35 the transparency would be 17. I’ll tweak the script and give you any updates if it works or not.

1 Like

It doesn’t work.

I was going to add a limit to how opaque it could get.
Here’s the script:

AirValue = game.Players.LocalPlayer.Character.Water.Air
TransparencyObj = script.Parent.LowOxygenEffect

while true do
	if AirValue <= 35 then
		TransparencyObj.BackgroundTransparency = AirValue * 2
		wait(0)
	elseif AirValue >= 35 then
		TransparencyObj.BackgroundTransparency = 1
	end
end

I don’t see why it doesn’t work.

1 Like

I’ll create a seperate topic. Thanks for helping!

1 Like