Attempting to make a status effect indicator but coming across child removed/added errors

  1. What do you want to achieve? Find out what the problem is

  2. What is the issue? The child removed function seems to be ignoring the if statements or just somehow activating multiple times from one child being removed, and the child added function is just not working

heres my code

local function debris(particlename,length,name,character)
	local wrapperg = coroutine.create(function()
	task.wait(length)
	while character.HumanoidRootPart:FindFirstChild(particlename) do
		task.wait(.1)
	end
	if name then
		if character.Head.EffectGui:FindFirstChild(name) then
			character.Head.EffectGui:FindFirstChild(name):Destroy()
		end
	end
	end)
	coroutine.resume(wrapperg)
end

function module.fire(character : "Player's Character", damage : number)
	local wrap = coroutine.create(function()
	local s,f = pcall(function()
	local sound = script.burn:Clone()
	local h = character:FindFirstChild("Humanoid")
	local effect = script.fire:Clone()
	if h then
		if not character.Head.EffectGui:FindFirstChild("fire") then
		local image = script.ImageLabel:Clone()
		image.Image = "rbxassetid://10656056841"
		image.Name = "fire"
		image.Parent = character.Head.EffectGui
		debris("fire",damage / 2.5, "fire",character)
		end
		effect.Parent = character.HumanoidRootPart
		game.Debris:AddItem(effect,damage / 2.5)
		local connection = character.HumanoidRootPart.ChildAdded:Connect(function(child)
					if child:IsA("ParticleEmitter") then
						if child.Name == "fire" then
							if character.Head.EffectGui:FindFirstChild("fire") then
								local indicator = character.Head.EffectGui:FindFirstChild("fire")
								if indicator then
									indicator.Count.Value += 1
									indicator.TextLabel.Text = "x"..indicator.Count.Value
								end
							end
						end
					end
		end)
		local disconnect = false
		local connection2 = character.HumanoidRootPart.ChildRemoved:Connect(function(child)
			if child:IsA("ParticleEmitter") then
						if child.Name == "fire" then
							if not character.Head.EffectGui:FindFirstChild("fire") then
								disconnect = true
							end
							if character.Head.EffectGui:FindFirstChild("fire") then
								local indicator = character.Head.EffectGui:FindFirstChild("fire")
								if indicator then
									indicator.Count.Value -= 1
									indicator.TextLabel.Text = "x"..indicator.Count.Value
								end
							end
						end
			end
				end)
		for i = 1,damage do
			task.wait(0.2)
			if disconnect == true then
				disconnect = false
				connection2:Disconnect()
			end
			local sound = script.burn:Clone()
			sound.Parent = character.HumanoidRootPart
			sound:Play()
            game.Debris:AddItem(sound,.5)
			h:TakeDamage(1)
		end
		connection:Disconnect()
	end
	end)
	end)
	coroutine.resume(wrap)
end

any help would be appreciated