Global Functions

From Legacy Roblox Wiki
Revision as of 21:15, 23 September 2010 by >Sncplay42 (→‎Introduction: changing intro, things like :Clone() are unrelated)
Jump to navigationJump to search

Introduction

Have you ever wanted to share information between scripts without using the -Value objects? You can by using the _G table!

_G is a table that all scripts can read and change.

How a global command works

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:

_G["Bob"] = game.Workspace.Bob

If you're in a ScriptBuilder, you can exit that script and open a new one. Put this in it:

_G.Bob.Torso:Remove()

run that script, and Bob's torso gets removed! Why? Because when we made the assignment using _G["Bob"]=, we are creating an entry in the _G table, and we can reference that entry by calling "_G.Bob".

Getting a global function

_G["Lazer"] = function(person) 
person.Torso:Remove() 
end

Now exit that script, and run this script:

_G.Lazer(game.Workspace.Bob)

If your character's name is "Bob," you should have your torso removed.