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

Change Variables of Script 1 with a second script?

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

2 comments

0

Use BindableEvents

0

Use BindableEvents

1 answer

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

1 comment

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?

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