I would Like to know
There are a few ways I can think of to get variables from other scripts. I will list them below.
This, I think is the easiest of all of them, all you would have to do is add a _G.
to the beginning of every variable used. However, it is not recommended to use this method.
First Script
_G.Hello = 'I am a Global Variable!'
Second Script
print(_G.Hello) -- >I am a Global Variable!
In one script, you can Invoke the object to return a preferred variable to you from another script. I think the code will simplify it (since I am not sure how to put it in basic terms).
First Script
Instance.new('BindableFunction',game.ServerStorage).Name = 'Bind' --This will set up the bindable function. local Hello = 'I am a Regular Variable, I am being used by another script!' --Define the variable. function game.ServerStorage.Bind.OnInvoke(--[[Tuple Arguments can be added here, may help if you want just one variable out of many.]]) --Since it's a callback, you must set up the function like this (either this or I have no way around it). --Also, since this is a BindableFunction, we can return a value. So we will return that Hello value when asked to. return Hello --This will return the value. end
Second Script
print(game.ServerStorage.Bind:Invoke()) --The output should be >I am a Regular Variable, I am being used by another script!
Modules can basically store and return values in a table. I am not sure if you can edit these variables though and they would be heard script to script (then again, I have never tested it). All you would have to do is call for the script, and get the desired variable.
Module Script
local Var = { Hello = 'I am a Regular Variable, I am being used by another script!' } return Var
Regular Script
Var = require(game.ServerScriptService.ModuleScript) --We'll just assume the module will be in there. print(Var.Hello) --This will look through the table of variables you set up, and it will find '.Hello' then it should print >I am a Regular Variable, I am being used by another script!
I am sorry I did not go into more detail explaining things, I am not sure about some of these techniques being used throughout an entire script. If you understand it, then that's great, if you're confused about a particular area let me know.
Sure you can. There's a reason that Roblox has Value
instances. These are able to store variables, and you can access them from any script. As an example, I'll show you how to get the players name from the LocalScript, then access it from the regular Script.
Say I have a StringValue, a Script, and a LocalScript, all inside of a player's Playergui.
Now, we'd be able to get the players name from the LocalScript by doing this:
Name=game.Players.LocalPlayer.Name --Gets name script.Parent.StringValue.Value=Name --Puts name in StringValue
Now, here's how we would be able to get the name from the regular Script:
Name=nil --Sets the variable for name repeat wait() until script.Parent.StringValue.Value~="" --This checks to make sure that the players name is there. Name=script.Parent.StringValue.Value --Sets the 'Name' variable to the players name.
Anyways, this is just one example of how you would be able to do this. It can also be done with Objects, Bools, and Numbers. If you have any further questions, please leave a comment below. Hope I helped clarify this for you. :P
Locked by Redbullusa and M39a9am3R
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?