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

Why doesn't setting a part to nil destroy it?

I tried this:

script.Parent.Touched:Connect(function(Hit)
	Hit = nil
end)

Setting a part to nil should destroy it, why doesn't this work?

3 answers

✓ Accepted answer

Hello, this is really simple. The reason why nil doesn't remove the instance is that nil is a directory, which is not accessible through scripts. Let's say that nil is the Workspace, but you cannot access it.

Like the person above said, to remove the part you can do

Hit:Destroy()

or

Hit:Remove()

and the part will be wiped off your game.

Nil can be used for many things, such as anti-cheats. The bad part is that exploits parent their scripts to nil so the game cannot detect them.

~ Dan_PanMan, advanced scripter.

2 comments

0

That's not reason. It won't remove it because he's setting Hit to nil. The variable Hit, not its value

0

I didn't understand anything you said, but okay lmao.

No, "setting a part to nil" doesn't destroy it. You were close though. Parenting a part to nil is probably what you were thinking of Hit.Parent = nil however I wouldn't recommend doing that. It's better to :Destroy() it.

script.Parent.Touched:Connect(function(Hit)
	Hit:Destroy()
end)

1 comment

0

Using Hit.Parent = nil is useful when you might want to retrieve it later though. Just in case he might have wanted that.

Either use Hit.Parent = nil or use Hit:Destroy or Hit:Remove.

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