Help with custom healing system

So I’ve made my own healing script, after getting damage in 3 seconds it starts healing player and wont stop before player reach maximum health.

Issue is that i want heal to stop whenever player get damage while hes HEALING, but if i do something like checking up if player got damage while healing it counts healing as getting “damage” cuz it still changes the value.

So theres no difference for script if it was decrease or increase of health. I need to fix it somehow but I cant get how
I tried to figure out when health changes did it increase or decrease but still didnt realise how to do that

Hope yall understand something from what i said
Also sry for weird script


local Assets = {
	Particle = script:WaitForChild("Healing Particle")
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:FindFirstChildOfClass("Humanoid")
		
		char:SetAttribute("Heal", false)
		local heal = false
		local fullhp = true
		
		local particle = Assets.Particle:Clone()
		particle.Parent = char.PrimaryPart

		hum.HealthChanged:Connect(function()

			if hum.Health ~= hum.MaxHealth then
				fullhp = false
			end

			spawn(function()
				task.wait(3)

				if heal == false and fullhp == false and hum.Health > 0 then
					heal = true
					particle.Enabled = true
				end
			end)
		end)

		while true do
			if heal == true and hum.Health > 0 then
				hum.Health += hum.MaxHealth/100
			end

			if hum.Health == hum.MaxHealth then
				heal = false
				fullhp = true
				particle.Enabled = false
			end

			task.wait(0.1)
		end
	end)
end)

``
1 Like

Hmm maybe something like this

local lasthp = hum.Health
hum.HealthChanged:Connect(function()
           if lasthp > hum.Health then
                  Print(“Took damage”)

                  else

                  Print(“Healed”)
           end

            lasthp = hum.Health
			if hum.Health ~= hum.MaxHealth then
				fullhp = false
			end

			spawn(function()
				task.wait(3)

				if heal == false and fullhp == false and hum.Health > 0 then
					heal = true
					particle.Enabled = true
				end
			end)
		end)
1 Like

I just got banned, ill try that tomorrow! :smiley:

1 Like

Bummer! … keep in mind there is a healing script in the character. This script will not play well with other heal scripts.

I turned roblox heal script off by making empty localscript with the same name

2 Likes

It worked!

Heres the script if anyone wonder:


local Assets = {
	Particle = script:WaitForChild("Healing Particle")
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:FindFirstChildOfClass("Humanoid")
		
		local lasthp = hum.Health

		local heal = false
		local fullhp = true
		
		local particle = Assets.Particle:Clone()
		particle.Parent = char.PrimaryPart

		hum.HealthChanged:Connect(function()
			
			if hum.Health ~= hum.MaxHealth then
				fullhp = false
			end
			
			if lasthp > hum.Health then
				--print("Took damage")
				heal = false
				particle.Enabled = false
				spawn(function()
					task.wait(3)

					if heal == false and fullhp == false and hum.Health > 0 then
						heal = true
						particle.Enabled = true
					end
				end)
			else
			end
			lasthp = hum.Health
		end)

		while true do
			if heal == true and hum.Health > 0 then
				hum.Health += hum.MaxHealth/100
			end

			if hum.Health == hum.MaxHealth then
				heal = false
				fullhp = true
				particle.Enabled = false
			end

			task.wait(0.1)
		end
	end)
end)

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