How do I fix this hitbox spawning mechanism

The code shown below is my hitbox spawning function, its a local function that works around a factory which spawns hitbox objects in terms of the data provided. the issue i’m having is that getting is in the deleting of the hitbox, when the hitbox is deleted for any reason (eg. hitting an enemy) its designed to delete itself, but I’m now getting this error around ``Instance (null) not found I assume this means that it can’t find hitbox due to it being deleted, how can I get around this issue?

local function SpawnHitbox(self, x, y, duration, startup)
	local AttackStateCheck = self.State
	timer.delay(startup, false, function()
		if AttackStateCheck ~= self.State then
			return
		end
			self.AttackBlock = true
			if self.FacingRight == false then
				x = x * -1
			end
			local hitPos = go.get_position() + vmath.vector3(x, y, 0)
			local hitbox = factory.create("#factory", hitPos)
			msg.post(hitbox, "set_parent", { parent_id = go.get_id(), keep_world_transform = 1 })
			go.animate(hitbox, "position.x", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 200)
			timer.delay(duration, false, function()
				self.AttackBlock = false
				if hitbox ~= nil then
					go.delete(hitbox)
				end
			end)
		end
	end)
end

You can use go.exists to check before deleting or alternatively store hitboxes in a lookup table in a module when creating them and remove them when deleting go and just check if the hitbox is in that table before performing something to that go, though that might be overkill for your use case.

Cheers!