local function onHealthChanged(Health)
if Health <= 0 and not self.Dead then
self.Dead = true
Debris:AddItem(self.NPC, 0)
self = nil
end
end
Hum.HealthChanged:Connect(onHealthChanged)
That is a code snippet including just the code section with the problem, the whole code contains a metatable and functions.
Mob = {}
Mob.__index = Mob
function Mob:Start()
local Hum = self.NPC:WaitForChild("Humanoid")
local CurrentHealth = Hum.Health
local function onHealthChanged(Health)
if Health < CurrentHealth then
self:HitEffect()
end
if Health <= 0 and not self.Dead then
self.Dead = true
self.Clone.Parent = game.Workspace
NPCManager.Initialize(self.Clone)
Debris:AddItem(self.NPC, 0)
self = nil
end
end
Hum.HealthChanged:Connect(onHealthChanged)
end
end
^Still not the full code but its showing the main function and the table
in the Initializing function.
The code runs all good until the debris, which deletes the model but keeps the UI.
No need to check other sources of error outside the snippet in the post.