I want to know if you can make a variable in one script, and then access it from another one. Is this possible?
COMMUNITY QUESTION
Is it possible to make a variable that can be accessed by another script?
2 answers
There are 4 ways to do this. You can use a module script (CLICK FOR VIDEO), you can use Values, or you can use a BindableEvent to request the information which another event is fired to send it back. Another one would to use Global Variables. This isn't recommended though. I recommend Values or ModuleScript. BindableEvents would be a last resort.
2 comments
0
Thanks! I will watch the video.
0
Actually there are 4 ways. You forgot _G. The other 3 are considered as better, I also would recommand module or BindableEvent.
What I generally use modules. But you can use BindableEvents, etc.
ModuleScript
local module = {}
function module.newfunction(x)
print(x)
end
return module
Then you use a require function to "call" the module.
Server:
local newmodule = require(modulescriptlocation) -- make sure the argument is the modulescript object
newmodule.newfunction("hi")
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Yah use module scripts
explain more...