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

Change Variables of Script 1 with a second script?

Asked by 5 years ago

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

0
Use BindableEvents piRadians 297 — 5y
0
Use BindableEvents piRadians 297 — 5y

1 answer

Log in to vote
0
Answered by
angeI1001 123
5 years ago

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

0
Thank you, then I will use a ModuleScript. But do you know how I can change the variable I mentioned using the second script? nicolinooAT 0 — 5y
Ad

Answer this question