Global function

(Redirected from Global Functions)

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[edit]

In one server script:

_G.foo = function()
	print("bar")
end

In another server script:

_G.foo()
--> bar

See also[edit]