Hello,
I am extremely new at scripting and I already have a question. How can I change a Variable of Script 1 (_G.colornow = _G.blue
) with clicking on a button using the second script?
I have two scripts, the first one defines colors and makes a brick change it's color when it gets clicked:
_G.black = BrickColor.Black() _G.red = BrickColor.Red() _G.blue = BrickColor.Blue() _G.green = BrickColor.Green() _G.erase = BrickColor.White() _G.colornow = _G.blue script.Parent.MouseClick:connect(function() game.Workspace.Folder.Part.BrickColor = (_G.colornow) end)
And the second script should change the Variable _G.colornow to one of the colors above when a button is clicked:
script.Parent.MouseButton1Click:connect(function() --Here I need to change the variable _G.colornow end)
I already thank you in advance.
Regards, nicolinooAT aka. Nico
I'd recommend you to use a ModuleScript instead of using _G.
More about modulescripts: https://www.robloxdev.com/api-reference/class/ModuleScript
I hope this helped you.
If you want to know more about why you shouldn't use _G. instead of a modulescript, you can read this article: https://devforum.roblox.com/t/g-or-modulescripts/173421