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

How to use global functions?

In one script I have this code:

_G["chick"] = function() print("chicken") end

And in another script I have this code that activates on tool click:

_G.chick()

But I get this message: attempt to call field 'chick' (a nil value)

Even with the command line I get the same message.

How should I do this? I can tell my code will be terrible if I have to copypaste through every tool.

1 answer

✓ Accepted answer

The globals table for client-side and server-side scripts is completely different, meaning that you can't create a global variable (or function) in a server-side script and use it from a client-side script (the same applies in the opposite example).

Why not use a ModuleScript?

http://wiki.roblox.com/index.php?title=Module_scripts

1 comment

0

While I have been using server side scripts both times, this seems to work better than the global functions I was planning to use,. Thanks!

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