Zombie doesn't despawn

local lighting = game.Lighting

local spawnsfolder = script.Parent
local zombie = game.ReplicatedStorage.Zombie

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if lighting.ClockTime == 18 then
		for i,spawns in pairs(game.Workspace.ZombieSpawnFolder:GetChildren()) do
			if spawns:IsA("BasePart") and spawns.Name == "ZombieSpawn" then
				local ZC = zombie:Clone()
				ZC.Parent = game.Workspace.ZombieFolder
				ZC.Name = "Zombie"
				ZC.HumanoidRootPart.CFrame = CFrame.new(spawns.Position + Vector3.new(0,5,0))
			end
		end

	end
	
	if lighting.ClockTime == 6.4 then
		for i,v in pairs(workspace.ZombieFolder:GetChildren()) do
			v:Destroy()
			print(i.." | gone")
		end
	end
end)


The zombie just doesn’t de-spawn.

first off, I recommend using game.Debris:AddItem(v,0) instead of v:Destroy

I think the main issue is your ingame clock might be moving too fast for the script, this causes an issue where the time updates and it isn’t exactly 6.4, to fix this try doing

if math.abs(lighting.ClockTime - 6.4) <= 0.1 then
1 Like