I want to know if you can make a variable in one script, and then access it from another one. Is this possible?
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.
What I generally use modules. But you can use BindableEvents, etc.
ModuleScript
1 | local module = { } |
2 | function module.newfunction(x) |
3 | print (x) |
4 | end |
5 | return module |
Then you use a require
function to "call" the module.
Server:
1 | local newmodule = require(modulescriptlocation) -- make sure the argument is the modulescript object |
2 |
3 | newmodule.newfunction( "hi" ) |