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

How do you change a variable's value in a script by using another script?

Asked by
314cake 17
6 years ago

I'm trying to change a variable's value in a script that only appears when the game starts, so I'll have to do that from another but I don't know how

0
Could you explain this a bit more? I guess if you want to affect the script's code you could use a ModuleScript, but this is based on a guess considering I don't know what it is you want exactly! User#20989 0 — 6y
0
You can also make a value in ReplicatedStorage or ServerStorage that both scripts can watch and/or update mattscy 3725 — 6y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

You can use the _G, which is a table shared by all scripts. Usage:

script1:

wait(5);
_G.variablesValue = 10;

script2;

repeat wait() until _G.variablesValue == 10
print("yuht");

Notes..

  • _G is shared between Scripts
  • _G is shared between LocalScripts
  • _G is not shared between Scripts and LocalScripts
  • _G is not shared between mutliple clients' LocalScripts
Ad

Answer this question