Health Bar Thing

I made a somewhat terrible health bar.
It doesnt work.

--	 _____	_________	 _______   _____    __			_________   __    __
--	/  __/ |___  ___|  / _____|  /     \  /  |	   |___  ___| 	/ |   | \
-- /  /_	   | |     | |____   |  /\  | |  /           | |     |  |__|  |
-- \___ \	   | |     |  ____|  | |__| | | |            | |     |   __   |
-- ___/ /	   | |     | |____   |  __  | | |_____       | |     |  |  |  |
--|____/ 	   |_|     \______|  |_|  |_|	\______|	   |_|     |__|  |__|


--[[ Health Levels: 
rbxassetid://8158941328 - Full Heart
rbxassetid://8159271589 - Half Heart
rbxassetid://8159292027 - Empty Heart
]]--
local Character = workspace:WaitForChild(game.Players.LocalPlayer.Name) 
 


local Health = Character:WaitForChild("Humanoid").Health

-- 15, 30, 45, 60, 75, 90


	

	
while true do
	
	wait(.5)
	
	if Health == 100 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8158941328" -- Full
		
	elseif Health < 90 or Health == 90 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8159271589" -- Half
		
	elseif Health < 75 or Health == 75 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
		
	elseif Health < 60 or Health == 60 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8159271589" -- Half
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
		
	elseif Health < 45 or Health == 45 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
		
	elseif Health < 30 or Health == 30 then
		script.Parent.Health.Health1.Image = "rbxassetid://8159271589" -- Half
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
		
	elseif Health == 0 then
		script.Parent.Health.Health1.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
	end	
	end









1 Like

Recommend you to use a function that only detects the Health Change when the Health of the Humanoid changes, this may not help with the error but it can give you some perfomance.

1 Like

Your problem is that you’re storing the immediate health number value into the Health variable instead of the object.

Try doing this instead.

--	 _____	_________	 _______   _____    __			_________   __    __
--	/  __/ |___  ___|  / _____|  /     \  /  |	   |___  ___| 	/ |   | \
-- /  /_	   | |     | |____   |  /\  | |  /           | |     |  |__|  |
-- \___ \	   | |     |  ____|  | |__| | | |            | |     |   __   |
-- ___/ /	   | |     | |____   |  __  | | |_____       | |     |  |  |  |
--|____/ 	   |_|     \______|  |_|  |_|	\______|	   |_|     |__|  |__|


--[[ Health Levels: 
rbxassetid://8158941328 - Full Heart
rbxassetid://8159271589 - Half Heart
rbxassetid://8159292027 - Empty Heart
]]--
local Character = workspace:WaitForChild(game.Players.LocalPlayer.Name) 



local Humanoid = Character:WaitForChild("Humanoid")

-- 15, 30, 45, 60, 75, 90





while true do

	wait(.5)

	if Humanoid.Health == 100 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8158941328" -- Full

	elseif Humanoid.Health < 90 or Humanoid.Health == 90 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8159271589" -- Half

	elseif Humanoid.Health < 75 or Humanoid.Health == 75 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty

	elseif Humanoid.Health < 60 or Humanoid.Health == 60 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8159271589" -- Half
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty

	elseif Humanoid.Health < 45 or Humanoid.Health == 45 then
		script.Parent.Health.Health1.Image = "rbxassetid://8158941328" -- Full
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty

	elseif Humanoid.Health < 30 or Humanoid.Health == 30 then
		script.Parent.Health.Health1.Image = "rbxassetid://8159271589" -- Half
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty

	elseif Humanoid.Health == 0 then
		script.Parent.Health.Health1.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health2.Image = "rbxassetid://8159292027" -- Empty
		script.Parent.Health.Health3.Image = "rbxassetid://8159292027" -- Empty
	end	
end

Also, I recommend using the HealthChanged function instead. It’s a function of Humanoid. Read the following article for tips.
https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

2 Likes
--	 _____	_________	 _______   _____    __			_________   __    __
--	/  __/ |___  ___|  / _____|  /     \  /  |	   |___  ___| 	/ |   | \
-- /  /_	   | |     | |____   |  /\  | |  /           | |     |  |__|  |
-- \___ \	   | |     |  ____|  | |__| | | |            | |     |   __   |
-- ___/ /	   | |     | |____   |  __  | | |_____       | |     |  |  |  |
--|____/ 	   |_|     \______|  |_|  |_|	\______|	   |_|     |__|  |__|


--[[ Health Levels: 
rbxassetid://8158941328 - Full Heart
rbxassetid://8159271589 - Half Heart
rbxassetid://8159292027 - Empty Heart
]]--

local HealthLevels = {0, 17, 34, 51, 68, 85, 100}
local HealthImages = {"rbxassetid://8158941328", "rbxassetid://8159271589", "rbxassetid://8159292027"} --Full, Half, Empty.
local Gui = script.Parent
local Frame = Gui:WaitForChild("Health")
local Health1 = Frame:WaitForChild("Health1")
local Health2 = Frame:WaitForChild("Health3")
local Health3 = Frame:WaitForChild("Health3")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.HealthChanged:Connect(function(Health)
	if Health == HealthLevels[7] then
		Health1.Image = HealthImages[1]
		Health2.Image = HealthImages[1]
		Health3.Image = HealthImages[1]

	elseif Health <= HealthLevels[6] then
		Health1.Image = HealthImages[1]
		Health2.Image = HealthImages[1]
		Health3.Image = HealthImages[2]

	elseif Health <= HealthLevels[5] then
		Health1.Image = HealthImages[1]
		Health2.Image = HealthImages[1]
		Health3.Image = HealthImages[3]

	elseif Health <= HealthLevels[4] then
		Health1.Image = HealthImages[1]
		Health2.Image = HealthImages[2]
		Health3.Image = HealthImages[3]

	elseif Health <= HealthLevels[3] then
		Health1.Image = HealthImages[1]
		Health2.Image = HealthImages[3]
		Health3.Image = HealthImages[3]

	elseif Health <= HealthLevels[2] then
		Health1.Image = HealthImages[2]
		Health2.Image = HealthImages[3]
		Health3.Image = HealthImages[3]

	elseif Health == HealthLevels[1] then
		Health1.Image = HealthImages[3]
		Health2.Image = HealthImages[3]
		Health3.Image = HealthImages[3]
	end	
end)