--updated 10/09/2022


npc= nil
hum= nil
health_gui= script.Parent
health_text= script.Parent:WaitForChild("TextLabel")


if (health_gui.Parent~= nil and health_gui.Parent.ClassName== "Model" and health_gui.Parent:FindFirstChildOfClass("Humanoid")) then
	npc= health_gui.Parent
	hum= health_gui.Parent:FindFirstChildOfClass("Humanoid")
	
elseif (health_gui.Parent.Parent~= nil and health_gui.Parent.Parent.ClassName== "Model" and health_gui.Parent.Parent:FindFirstChildOfClass("Humanoid")) then
	npc= health_gui.Parent.Parent
	hum= health_gui.Parent.Parent:FindFirstChildOfClass("Humanoid")
	
elseif (health_gui.Parent.Parent.Parent~= nil and health_gui.Parent.Parent.Parent.ClassName== "Model" and health_gui.Parent.Parent.Parent:FindFirstChildOfClass("Humanoid")) then
	npc= health_gui.Parent.Parent.Parent
	hum= health_gui.Parent.Parent.Parent:FindFirstChildOfClass("Humanoid")
end


if not npc then
	health_gui:Remove()
end

if not hum then
	health_text.Text= "humanoid not found"
	health_text.TextColor3= Color3.fromRGB(255, 255, 127)
end

hum.DisplayDistanceType= Enum.HumanoidDisplayDistanceType.None
hum.HealthDisplayType= Enum.HumanoidHealthDisplayType.AlwaysOff


game["Run Service"].Heartbeat:Connect(function()
	
	--for text health
	health_text.Text= npc.Name.. " | ".. hum.Health.. " / ".. hum.MaxHealth
	
	--for color
	local GoodColor= Color3.fromRGB(85, 255, 127)
	local MediumColor= Color3.fromRGB(255, 255, 127)
	local BadColor= Color3.fromRGB(255, 140, 142)

	if hum.Health >= hum.MaxHealth * 0.6 then
		health_text.TextColor3= GoodColor
	end
	
	if hum.Health <= hum.MaxHealth * 0.6 then
		health_text.TextColor3= MediumColor
	end
	
	if hum.Health <= hum.MaxHealth * 0.25 then
		health_text.TextColor3= BadColor
	end
	
end)
