[Solved] My problem 3

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

  1. What do you want to achieve? Keep it simple and clear!
    error.
  2. What is the issue? Include screenshots / videos if possible!
    Not working and no errors popping up on output too.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried converting it to a function and it still doesn’t work. Am I doing something wrong?
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
if humanoid.healthischange then
		script.Parent.HPBar.cr=
		script.Parent.HPBar.cr = 
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Is this just it? Then you can use GetPropertyChangedSignal to detect when the health changes

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.health < humanoid.MaxHealth then
	wait(0.25)
	script.Parent.HPBar.ImageColor3 = Color3.new(1, 0.309804, 0.309804)
	wait(0.5)
	script.Parent.HPBar.ImageColor3 = Color3.new(1, 1, 1)
	end
end)

If it doesn’t work or you already did that then try adding prints to see if it’s running, I tested this and there’s nothing wrong with your code apparently

1 Like

You can save the player’s health and check if the player’s current health is less than the initial health

local lastHealth = humanoid.Health
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	if humanoid.Health < humanoid.MaxHealth then
		if humanoid.Health >= lastHealth then 
			lastHealth = humanoid.Health
			return
		else
			lastHealth = humanoid.Health
			wait(0.25)
			script.Parent.HPBar.ImageColor3 = Color3.new(1, 0.309804, 0.309804)
			wait(0.5)
			script.Parent.HPBar.ImageColor3 = Color3.new(1, 1, 1)
		end
else lastHealth = humanoid.Health
	end
end)

If the player’s health increased then it won’t change color anymore

3 Likes

I would rather use HealthChanged method Humanoid | Documentation - Roblox Creator Hub

local FLASH_COLOR = Color3.new(1, 0.309804, 0.309804)
local ORIGINAL_COLOR = script.Parent.HPBar.ImageColor3

local lastHealth = humanoid.Health

humanoid.HealthChanged:Connect(function(health)
	if health < lastHealth then
		lastHealth = health
		task.wait(0.25)
		script.Parent.HPBar.ImageColor3 = FLASH_COLOR
		task.wait(0.5)
		script.Parent.HPBar.ImageColor3 = ORIGINAL_COLOR 
	end
	
	lastHealth = health
end)
2 Likes

thank you for fixing my problem. Appreciate it!

1 Like

Thank you too! Appreciate the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.