Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

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!

0

You can also make a value in ReplicatedStorage or ServerStorage that both scripts can watch and/or update

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.