Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
nc2r 117
3 years ago
Edited 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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.

0
That's not reason. It won't remove it because he's setting Hit to nil. The variable Hit, not its value oreoollie 649 — 3y
0
I didn't understand anything you said, but okay lmao. Dan_PanMan 227 — 3y
Ad
Log in to vote
1
Answered by
oreoollie 649 Moderation Voter
3 years ago

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)
0
Using Hit.Parent = nil is useful when you might want to retrieve it later though. Just in case he might have wanted that. Benbebop 1049 — 3y
Log in to vote
0
Answered by 2 years ago

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

Answer this question