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

Is it possible to make a variable that can be accessed by another script?

Asked by 6 years ago

I want to know if you can make a variable in one script, and then access it from another one. Is this possible?

0
Yah use module scripts User#19524 175 — 6y
0
explain more... RetroGalacticGamer 331 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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.

0
Thanks! I will watch the video. RetroGalacticGamer 331 — 6y
0
Actually there are 4 ways. You forgot _G. The other 3 are considered as better, I also would recommand module or BindableEvent. jaschutte 324 — 6y
Ad
Log in to vote
0
Answered by
piRadians 297 Moderation Voter
6 years ago

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") 

Answer this question