Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Object got inserted into a table, Object got destroyed, Table stays as original O_O?

Is there a way I can detect the object is destroyed?

Experiment script:

local mytable = {} 
local part = workspace.Part 
table.insert(mytable,part) 
print(#mytable) --Prints 1 '_'
part:Destroy() 
print(#mytable) --Prints 1? 0_0
print(mytable[1]) --Prints Part? O_O

1 comment

0

Fluff my stupid brain! I just only have to check the parent is nil or not.

1 answer

You're maintaining a reference to the part, which will prevent it from being garbage collected, and mytable hasn't been garbage collected when you run your prints.

You could remove it from the table yourself, or use a weak table with the values being weak (__mode = "v"):

http://wiki.roblox.com/index.php/Weak_tables

This discussion is preserved as it was. New answers, comments, and votes are closed.