Does calling script:Destroy() inside a LocalScript actually destroy it on client?


Recently I found out that calling script:Destroy() inside a local script does not stop it from working if there are variables defined locally. I find it useful as I can use this to make my local scripts less exposed and harder to access, but does that mean it can’t be accessed at all (on client)?

Yes, if you call Instance:Destroy() it won’t be possible to access unless you already have it stored somewhere in a variable

1 Like

it will stop running the code but for some of the task libraries it will still run. Like if you had a while task.wait() do loop it will still run.

1 Like

Just curious, is the script being completely inaccessible for potential exploiters or just like script.Parent = nil, just hides it?

Calling destroy will disconnect, lock every property and call nil on everything. That is if you’re a nerd that pretends the data is still there. It’s not. It gets literally deleted unless there’s some reference to it like a variable (which now points to nil)

You can hide the environment

So is using getfenv().script:Destroy() instead of just script:Destroy() safer?

Logically identical, but calling getfenv() prevents certain optimizations in Luau.

1 Like