Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to call a global function in another script?

Alright, so I've been looking for the answer to this question for a while, but never found it. What I want to do is have all my Functions and Variables in one script then be able to call then in a different script.

For example:

_G.BaseScriptName.GlobalFunction = function(Args)
	-- CODE HERE
end

Then I want to be able to call it in a different script like:

_G.BaseScriptName.GlobalFunction(Args)

Basicly the problem is when I call it, it gives this error:

Workspace.Script:3: attempt to call field 'GlobalFunction' (a nil value)

Any help is appreciated :D

2 comments

0

you need to define the BaseScriptName

0

I just posted a comment.

2 answers

in script one you had

_G.BaseScriptName.GlobalFunction = function(Args)
    -- CODE HERE
end

make it have this at the top it will fix it. _G.BaseScriptName = {}

_G.BaseScriptName = {}

_G.BaseScriptName.GlobalFunction = function(Args)
    -- CODE HERE
end

It is simply a index, but you never created the house to the door in other words.#

If I helped upvote my answer .

I have the _G.BaseScriptName = {} table, but the function only works in the base script itself and the command line in studio.

Im obviously missing something VERY essential

I didnt really make myself clear, This is what I have:

_G.BaseScript = {}

_G.BaseScript.OutputLine = function(Line)
	print(Line)
end

1 comment

0

But the problem is when calling it in the other script it just gives an error

This discussion is preserved as it was. New answers, comments, and votes are closed.