Destroy() and nil or just nil

Should i use Destroy() and nil then or just nil?


Can we get some context in what your looking to do? That question really depends on what your trying to do, for example are you trying to destroy an instance or invalidate something inside of table. Both of them are completely different and would need different ways.

A Gui, i tried it now if i make it nil i cant use the Frame anymore but i can see it, does that mean nil just disconnects all the thinks inside?

What property are you trying to change? I don’t know of any proterties in a UI that you would set it to nil.

If you want a frame to become invisible and cannot be used why don’t you just change the visible propriety to false?

I know that, i just wanted to know if i should just use nil or Destroy and nil both, but i tested it and to just make it nil would not make the Frame unvisible

What do you mean by Destroy or nil? If you want to make a frame invisible temporally just set the visible property to false. If you rather it just be removed completely just use :Destroy().

I don’t really understand what you don’t understand in regards to this? I kinda at this point wondering if this is just a troll post or if your really not understanding.

I did understand that all, i also know that i can make it Visible, im scripting for 2 years, but my Question was when i want to Destroy a Frame or else, should i use Destroy() and nil or just nil? Because i read in other Posts that nil is the same as Destroy(), but i tried to just make it nil and the Frame would not Destroy the Frame u would just not be able to use it.

Use destroy, it removes all the connections related to the object and sets its parent to nil.

1 Like

If you wanted to use nil, you can set the frame’s parent to nil:

frame.Parent = nil

1 Like

If you want to destroy an instance then just use :Destroy().

I don’t see how you have been scripting for 2 years and have never had to destroy an instance…

I had, im using Destroy() and nil all the Time, like i said u over me in the Text "Because i read in other Posts that nil is the same as Destroy()", i wanted to know if thats really the same or not.

I personally would recommend just using :Destroy(). I have honestly never heard anyone saying about setting the parent to nil.

I tested it rn, you can also test it, if you Destroy a Part, GUI, etc… and print it, it will print but not with nil:

local part = workspace.Part

part.Name = "Hey"


print(part.Name) -- It will print "Hey" but not with nil

Yes, the part is actually still there, it’s parent is nil, just because it’s parent is nil doesn’t mean it’s properties are nil, you can try to parent it to nil, wait 1 second, then reparent it back to whatever it was last time.
Edit : It is also the same for the children of Part

Yes because the part variable stores the instance/part inside of the instance (like stores the part object with the proprieties and stuff) so due to this even if you destroy it, it should still have the name property saved even when the part is destroyed.

If you want to make it so there is not the part saved there you can just like add an empty string or a nil or somthing.

It dont stores just one time u get the updated Part Status all the Time, i cant explain it, so if you add part = nil and then print(part) it then it would not print “Hey”, that means Destroy() is not destroying it completly

local part = workspace.Part

part.Name = "Hey"


part = nil

print(part.Name) -- Will not print "Hey"

Yes I know that. Like what I said, if you want to make the part variable to not equals to the part then you can just simply just make the variable nil. The reason why it does not print “Hey” is because your making the variable value equals to nothing in the code (by doing part = nil your not affecting the part itself at all but rather just changing the value of the variable).

That is completely invalid. Like I said in the reply above in this post the variable stores the part as an object inside of the variable called part and that is why the name does not change.

1 Like

part.Name is before you called part:Destroy()

destroying the part doesn’t mean that the variable will change.


Okay thanks, because i read somewhere that the Part will not Destroy completly until i set the Part to nil.

I have no idea who said that but that is completely incorrect. Are you sure that you did not misread it and the post means the variable will not be removed until the value is set to nil?