diff --git a/src/class.lua b/src/class.lua index 03a4e3d..2d7e68c 100644 --- a/src/class.lua +++ b/src/class.lua @@ -193,11 +193,11 @@ function module.init(shared) rawset(self,"__holder",object); if parent then rawset(self,"__parent",parent); - mount(item,parent) + mount(self,parent) end -- prevent gc ((type(object) == "table" and object.__object) or object):GetPropertyChamgedSignal "ClassName":Connect(function() - return item; + return self; end); return self; end @@ -222,13 +222,13 @@ function module.init(shared) if child then for _,v in pairs(child) do if v then - ((type(v) == "table") and rawget(v,"__object") or v).Parent = object; + v.Parent = object; end end end -- prevnet gc ((type(object) == "table" and object.__object) or object):GetPropertyChamgedSignal "ClassName":Connect(function() - return item; + return self; end); if lastObject then -- remove old instance self:Destroy(lastObject); diff --git a/src/mount.lua b/src/mount.lua index 2f13faf..3440783 100644 --- a/src/mount.lua +++ b/src/mount.lua @@ -33,9 +33,22 @@ function module.init(shared) local thisO = this; if type(this) == "table" then thisO = this.__object; + local parent = rawget(this,"__parent"); + if type(parent) == "table" then + local parentChild = rawget(parent,"__child"); + if parentChild then + for i,v in pairs(parentChild) do + if v == this then + parentChild[i] = nil; + end + end + end + end rawset(this,"__parent",to); end - thisO.Parent = inst or getHolder(to); + if thisO then + thisO.Parent = inst or getHolder(to); + end if type(to) == "table" then local child = rawget(to,"__child"); if not child then