Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cache = {}
- --[[
- cache = {
- className = {
- instance1,
- instance2
- ...
- }
- }
- ]]
- -- instance.new
- function getInstance(className, parent)
- local ins
- if cache[className]then
- ins = cache[className][1]
- if ins then
- table.remove(cache[className],1)
- end
- else
- cache[className] = {}
- end
- if not ins then
- ins = Instance.new(className)
- end
- if parent then
- ins.Parent = parent
- end
- return ins
- end
- -- destroy
- function cacheInstance(ins)
- local className = ins.ClassName
- cache[className] = cache[className] or {}
- table.insert(cache[className])
- ins.Parent = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement