Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to use global functions?

Asked by 9 years ago

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

Log in to vote
2
Answered by
DataStore 530 Moderation Voter
9 years ago

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

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! Zzzip42Strike 30 — 9y
Ad

Answer this question