Created
March 12, 2019 13:20
-
-
Save Kampfkarren/5b09086c8436138f1a9ceb33261b4392 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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