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