local a={}a.__index=a function a.GetInstance(f,a)if f.InstancePoolsByClass[a]==nil then f.InstancePoolsByClass[a]={}end local B=#f.InstancePoolsByClass[a]if B>0 then local l=f.InstancePoolsByClass[a][B]table.remove(f.InstancePoolsByClass[a])return l end return Instance.new(a)end function a.ReturnInstance(f,a)if f.InstancePoolsByClass[a.ClassName]==nil then f.InstancePoolsByClass[a.ClassName]={}end if#f.InstancePoolsByClass[a.ClassName]<f.PoolSizePerType then table.insert(f.InstancePoolsByClass[a.ClassName],a)else a:Destroy()end end

local methods = {}
methods.__index = methods

function methods:GetInstance(className)
  if self.InstancePoolsByClass[className] == nil then
    self.InstancePoolsByClass[className] = {}
  end
  local availableInstances = #self.InstancePoolsByClass[className]
  if availableInstances > 0 then
    local instance = self.InstancePoolsByClass[className][availableInstances]
    table.remove(self.InstancePoolsByClass[className])
    return instance
  end
  return Instance.new(className)
end

function methods:ReturnInstance(instance)
  if self.InstancePoolsByClass[instance.ClassName] == nil then
    self.InstancePoolsByClass[instance.ClassName] = {}
  end
  if #self.InstancePoolsByClass[instance.ClassName] < self.PoolSizePerType then
    table.insert(self.InstancePoolsByClass[instance.ClassName], instance)
  else
    instance:Destroy()
  end
end
