I saw in one of 'Games' games, the ROBLOX account named games. The script is supposed to not be shown, another thing to ask is how would I see that it's not there.
script = nil
If something needs to catch your eyes, here is the main focus.
script
is a global variable that's already set in your script environment (as you probably know). Setting the variable of script to nil
, will simply make it so you cannot reference your script anymore, which is probably not what you want to do. Going about this method would result in you not being able to use the "script" variable anymore in your code, unless you've assigned it some other value. For example:
script = nil script.Name = "test"
This code would result in an error similar to this in the output:
attempt to index global 'script' (a nil value)
Parent property
What you're probably asking is how does the statement script.Parent = nil
work. Which, is actually the same thing as using the Remove
or remove
method on an instance.
Parenting the script to nil, basically makes it so you can still reference the script, however anything else in the game cannot (essentially, removing the script from the game. As the method above I mentioned implies).
Summary
Anyway, needless lecture cut short, it removes the script from the game. If you have any further questions, just let me know.
Additional insight on environment tables
Because sometimes a big lecture can't cover everything
script
in itself is a member of the function environment. This means that it exists in a table which is referenced every time there's not a local value with the same name, which is convenient for Roblox because it's also where Roblox keeps all of the extra things like game
and workspace
.
What this means is that by setting script
to nil
, it is being removed from the function environment. This is really important to people who want to keep modules secret, because it means that people can't grab script
using getfenv
, which would allow them to save the script source and take a look at it.
It is also useful for people making and using script builders, as it's important that the script sandbox doesn't ever let the script access the Script object that it is running from. Of course, this is a primitive sandboxing method, but it's always a good start.
In this case, by removing the script from any Parent and setting the script
variable to nil, the script has become inaccessible to any external sources through any conventional means - Anything the script wants to do is likely to be exposed through _G
or Bindables in a lot of cases.