How do I fix my script so that NPC body parts despawn on death?

I have a game I am working on whereby NPCs spawn in at intervals, multiple different NPCs with different intervals. Everything works fine except for the fact that upon death, the body parts don’t despawn until the NPC respawns. Now, this is quite an issue when some of them don’t respawn for 5+ minutes, I don’t want the map littered with their body parts, but I am at a loss as to how to fix the issue.

This is the current script:

local ServerStorage = game:GetService(“ServerStorage”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local BossFolder = workspace:WaitForChild(“GladiatorFolder”)
local bosses = ServerStorage:WaitForChild(“Gladiators”)

local bossVar

while wait() do
wait(60)
local boss = bosses:GetChildren()[math.random(1,#bosses:GetChildren())]:Clone()
boss.Parent = BossFolder

boss:WaitForChild("Humanoid").HealthChanged:Connect(function()
	if boss.Humanoid.Health <= 0 then
		game.Debris:AddItem(bossVar,0)
		bossVar = nil
	end
end)
repeat wait(1) until boss:WaitForChild("Humanoid").Health == 0

local str = ""
game:GetService("ReplicatedStorage").Notification:FireAllClients(str)
boss:Destroy()

end

Any help would be appreciated!

Thank you in advance.

You were setting Debris to bossVar, and you never defined bossVar as the npc created, along with other issues in the script, test this one:

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local BossFolder = workspace:WaitForChild("GladiatorFolder")
local bosses = ServerStorage:WaitForChild("Gladiators")
local Debris = game:GetService("Debris")

while wait() do
	wait(5)
	warn("spawn npc")
	local boss = bosses:GetChildren()[math.random(1,#bosses:GetChildren())]:Clone()
	boss.Parent = BossFolder

	boss:WaitForChild("Humanoid").Died:Connect(function()
        warn("Boss Humanoid Died")
		Debris:AddItem(boss,3)
	end)

	local str = ""
	game:GetService("ReplicatedStorage").Notification:FireAllClients(str)
end

Unfortunately not. The NPC’s bodies still don’t despawn until the NPC itself respawns after the time elapsed.

Just bumping this as still in need of some help, if anyone else has some idea of how to solve the problem?

You are doing something wrong, I tested that code I sent in my message, and works normally, NPC despawns after 3 seconds without any issue, the code is pretty simple its impossible its not working, what else you doing? cause theres something else you are doing weird