ROBLOX How To's: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Blocco
(grammar fix)
>Emess
Line 73: Line 73:


===Global Functions===
===Global Functions===
Have you ever wondered how things like :Remove() and :Clone() always work, even though you've never indexed it? Here's how:
Have you ever wondered how functions like wait() always work, even though you've never indexed them?


If you know how to use the _G[] (global) command, this might come more easily to you than others. This is basically how a global command works:
You can, with _G.


_G["Bob"] = game.Workspace.Bob
Script 1:
<pre>_G.Player = game.Workspace.Player</pre>
Script 2:
<pre>_G.Player:remove()</pre>


If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:
If you are familiar with pure Lua, you should notice that we have to index _G before the variable name. Scripts will error without it, because of  security vulnerabilities.


Bob.Torso:Remove()
You can used shared instead of _G, if you want.
 
run that script, and your torso gets removed! Why? Because the _G[] (global) command makes "Bob" availible in every script. Now, to get a global function:
 
_G["Lazer"] = function(person) person.Torso:Remove() end
 
Now exit that, and do this:
 
Lazer(game.Workspace.Bob)
 
If your character's name is, "Bob," you should have your torso removed.


===Custom Objects===
===Custom Objects===
Anonymous user

Navigation menu