I am trying to make this script where it will set the Transparency of brickA to 1.
There is an intvalue and it is changed using another script
What kind of script is needed to make it constantly check if intvalue = 1 then brickA.Transparency = 1
Oh, theres a neat event called .Changed
for every Instance.
It passes an argument - the property changed, as a string.
You could use that to determine if the value has changed, and then change the transparency of the brick.
Alternatively, you could use a loop and check for the .Value
constantly, but that would be too much of a hassle.
Heres how to use .Changed
:
intValue.Changed:connect(function(property) if property == "Value" then if intValue.Value == 1 then --This looks better and shorter than 2 lines. brickA.Transparency = 1 end end end)
I'm adding on a bit to what Intern33t was saying
.Changed
is exactly what you're wanting. .Changed
will check to see if anything in that object, that you're checking, has changed. There are two ways, that I know of, to type this out, both using a :connect
which connects what the event was, .Changed
to the function we are wanting to run.
Example 1 :
Say I had a Integer Value that was changed by another script. I could check the change, and print something if it changed. In this example, I will be creating a function, defining it, and calling it whenever the value is changed.
local intValue = game.Workspace.IntValue function valueChanged(parameter) if parameter == "Value" then --This checks to make sure that the Value was the change. print('Changed') end end --Notice that there's no parenthesis for this end. intValue.Changed:connect(valueChanged) --This will call the function when changed.
Example 2:
Lets use the same example as the first one, but change it up a bit to make it more, what I call, organized.
local intValue = game.Workspace.IntValue intValue.Changed:connect(function(parameter) --This will call the function when changed. if parameter == "Value" then print('Changed') end end) --Notice that there's a parenthesis here.
In the first example, you'll notice that on that last end I had no parenthesis, whereas on the second example I had to use a parenthesis. That's because there's an open parenthesis on line 3 of example two that needs closing after your coding is typed.
I've told you a great deal of my knowledge about .Changed
, if you still don't understand, there's a helpful wiki page here.