Need a way to delete blur effect when player regenerates

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

  1. I need this blur effect to go away if the player isn’t losing health

  2. I’m not sure how to detect if the player is losing or gaining health

  3. I have messed around a little bit with the code and looked up the issue online and in the developer hub, and couldn’t really find anything specific to me]

This is my current code, I tried to disable the health script until the blur goes away, but it still doesn’t work. I can see that even if it did work it would still activate the blur when the script reactivated and end up giving weird blurry slow regen, so I just want to know if it is possible to detect when the player is healing/losing health.

local debris = game:GetService("Debris")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = workspace.Camera
local maxHealth = humanoid.MaxHealth

-- Creates blur effect on health change
humanoid.HealthChanged:Connect(function(newHealth)
	local blurCheck = camera:FindFirstChild("BlurEffect")
	if blurCheck then
		return 0
	end
	if newHealth < maxHealth then
		local damageBlur = Instance.new("BlurEffect",camera)
		local healthScript = character:FindFirstChild("Health")
		healthScript.Disabled = true
		damageBlur.Size = 10
		debris:AddItem(damageBlur,2)
		healthScript.Disabled = false
	end
end)
humanoid.Died:Connect(function()
       local blurCheck camera:FindFirstChild("BlurEffect")
       if blurCheck == nil then return end
       blurCheck:Destroy()
end)
1 Like

Thanks, I think I am just going to make the screen blur once the player reaches low health, and once they die it deletes. I don’t think there’s a way to check if the players health went up or down on a change.

Hey! This may be a bit late but maybe something like this could work:

local PreviousHealth = 100

humanoid.HealthChanged:Connect(function(newhealth)
	if newhealth > PreviousHealth then
		PreviousHealth = newhealth
		-- If they are regening
	elseif newhealth < PreviousHealth then
		PreviousHealth = newhealth
		-- If they are losing health
	end
end)
1 Like
if newhealth > PreviousHealth then
   PreviousHealth = newHealth

Doesn’t this only work once you regen past the previous health? As I’m looking around I am starting to think there isn’t a way to actually tell if the health change is a positive or negative one. Which is fine, it was just something I thought might be a cool effect for a fighting game, however, I think just making a blur that activated when your health reaches a certain point would work better and still be nice.
Thanks for the answer btw

Yeah, anyway you want to pursue it go ahaead. The idea of the code is that when it changes it sets the health to the old new value, so it will always be checking what the old value was. So if the player had 60 health it would set previous health to 60 so whether it increases or decreases it will check with 60 is lower than the current health or higher.

1 Like

Ah, alright, I’ve decided to just go with a blur when the player reaches low health, which I have got working perfectly at the moment. Thanks for your help.

1 Like