How would I be able to use a global function on a localscript?
You can use a global function on a local script.
The only thing that’s different is that the function will only apply to what local script is applying to.
It won’t be applied anywhere else.
1 Like
global function is every function that isn’t local.(Put _G before name of function, for example
_G.fun = function()
1 Like
_G.SomeFunction = function()
--is useful when it's a single function and is being used not too often, but many of your scripts are
--using it
end
And local script and global variable aren’t the same things.
1 Like
The recommended method is to use Modules.
--Module - let's say we put it in ReplicateStorage
local m = {}
m.Func = function()
print("Func")
end
return m
local module = require(game.ReplicatedStorage.Module)
module.Func()
You can also use the Global … type?.. modifer? (not sure what its called)
These are shareable between scripts of the same type (client / server - they don’t cross)
--script 1
_G.Func = function()
print("Global Func")
end
--script 2
_G.Func()
In both cases - if you create a global or reference a module on the client, it can only be shared on the client.
Same applies if you create a global/reference a module on the server.
6 Likes