PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Global Functions

Global Functions

Jul 03 2018, 9:55 AM PST 2 min

A global function is a function which is present in _G, also known as the global table. The same _G is accessible from any script, so putting a function in _G allows any script to call the function.

Keep in mind that the server has a different _G than clients do, so you can’t define a global function in a server script and then use it from a LocalScript.

You may want to consider using BindableFunctions and BindableEvents instead of global functions. If you need to communicate from client to server or server to client, then you should use RemoteFunctions and RemoteEvents.

Example

In one server script:

_G.hello = function ()
	print("world!")
end

In another server script:

_G.hello()
--> world!
Tags:
  • lua
  • coding
  • concept