Skip to content

Instantly share code, notes, and snippets.

@Kampfkarren
Created March 12, 2019 13:20
Show Gist options
  • Save Kampfkarren/5b09086c8436138f1a9ceb33261b4392 to your computer and use it in GitHub Desktop.
Save Kampfkarren/5b09086c8436138f1a9ceb33261b4392 to your computer and use it in GitHub Desktop.
local weakInstanceTable = {}
weakInstanceTable.__tostring = "<Weak Instance Table>"
function weakInstanceTable:__newindex(key, value)
assert(typeof(key) == "Instance", "keys need to be an Instance")
assert(key:IsDescendantOf(game), "key is not a descendant of the DataModel")
rawset(self, key, value)
key.AncestryChanged:connect(function()
if not key:IsDescendantOf(game) then
rawset(self, key, nil)
end
end)
end
return function()
return setmetatable({}, weakInstanceTable)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment