Simple script that enables a GUI does not function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I am doing whenever the Player is under 30 health, there would be a red screen.

  2. What is the issue? It does not work.

  3. What solutions have you tried so far? I had look for many post, I had unable to find one.

local Player = game.Players.LocalPlayer
local UI = Player.PlayerGui.status
local Frame = UI.Frame
local Character = Player.Character
local Humanoid = Character:WaitForChild('Humanoid')

if Humanoid.Health <= 30 then
	Frame.BackgroundTransparency = 0.8
	UI.Enabled = true
	print("Successful!")
else
	print("Something went wrong.")
end

if Humanoid.Health == 0 then
	Frame.BackgroundTransparency = 0
	wait(3)
	UI.Enabled = false
	print("Successful!")
else
	print("Something went wrong.")
end

-- This script is run in Localscript

This script should not be in that GUI, which is disabled, if a GUI is disabled, all its children will be disabled by default

if Humanoid.Health <= 30 then
	Frame.BackgroundTransparency = 0.8
	UI.Enabled = true
	print("Successful!")
else
	print("Something went wrong.")
end

Also this runs one time only, when the player spawns or the script is loaded

Try this script below:

humanoid.HealthChanged:Connect(function(healthnumber) -- 1-100
    if Humanoid.Health <= 30 then
	Frame.BackgroundTransparency = 0.8
	UI.Enabled = true
	print("Successful!")
    else
	print("Something went wrong.")
 end
end)

And don’t keep the script in the disabled GUI

Check this too:Humanoid.HealthChanged

Do I change the healthnumber that’s inside the function?

Nevermind, it worked. Thank you so much!

local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local PlayerGui = Player:WaitForChild("PlayerGui")
local UI = PlayerGui:WaitForChild("status")
local Frame = UI:WaitForChild("Frame")

Humanoid.HealthChanged:Connect(function(NewHealth)
	if NewHealth > 0 and NewHealth <= 30 then
		Frame.BackgroundTransparency = 0.8
		UI.Enabled = true
	elseif NewHealth <= 0 then
		Frame.BackgroundTransparency = 0
		task.wait(3)
		UI.Enabled = false
	end
end)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local PlayerGui = Player:WaitForChild("PlayerGui")
local UI = PlayerGui:WaitForChild("status")
local Frame = UI:WaitForChild("Frame")

Humanoid.HealthChanged:Connect(function(NewHealth)
	if NewHealth > 0 and NewHealth <= 30 then
		Frame.BackgroundTransparency = 0.8
		UI.Enabled = true
	end
end)

Humanoid.Died:Connect(function()
	Frame.BackgroundTransparency = 0
	task.wait(3)
	UI.Enabled = false
end)

This works, through if I heal all the way back it does not disable the UI.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local PlayerGui = Player:WaitForChild("PlayerGui")
local UI = PlayerGui:WaitForChild("status")
local Frame = UI:WaitForChild("Frame")

Humanoid.HealthChanged:Connect(function(NewHealth)
	if NewHealth > 30 then
		Frame.BackgroundTransparency = 1
		UI.Enabled = false
	end
end)

Humanoid.HealthChanged:Connect(function(NewHealth)
	if NewHealth > 0 and NewHealth <= 30 then
		Frame.BackgroundTransparency = 0.8
		UI.Enabled = true
	end
end)

Humanoid.Died:Connect(function()
	Frame.BackgroundTransparency = 0
	task.wait(3)
	UI.Enabled = false
end)