http://gyazo.com/0bcc53dc52248e52ddcc0c381e05f3aa -- That's a photo of the blog
If I do that code, will everything called "Brick" do what the rest of the code says when it's run?
Thanks IA
local brick = workspace.Brick
is an example of a variable. brick
now holds a value for you to use later. Instead of typing out workspace.Brick
every single time, you can now just use the word brick
, because it holds a value.
If you're in algebra, you're used to finding the value of variables like x
or y
. These variable stand for a number, just like brick
stands for a part in workspace.
Variables aren't necessary; These two examples do the same thing.
local brick = workspace.Brick brick.Transparency = 1
workspace.Brick.Transparency = 1
Here, the second example looks better, and it is. But what if you want to change the Transparency multiple times?
local brick = workspace.Brick brick.Transparency = 1 wait(1) brick.Transparency = 0 wait(1) brick.Transparency = 1 wait(1) brick.Transparency = 0
workspace.Brick.Transparency = 1 wait(1) workspace.Brick.Transparency = 1 wait(1) workspace.Brick.Transparency = 1 wait(1) workspace.Brick.Transparency = 1
Now the first example is quicker. Since we use the variable brick
, we don't have to type workspace.Brick
every single time.
Remember, there's nothing special about the word brick
. That's just the name we chose for our variable. You can name itWolfgangVonPrinz
if you want, and the code will do the same thing.
Just done some testing, I put two Brick parts in the workspace and added this script in to one of the parts:-
local del = true --only delete one part script.Parent.Touched:connect(function (part) if del then game.Workspace.Part:Destroy() del=false end --delete part and stop script end)
From what I can tell it seems to be choosing the fist instance of the brick called "Part" and deleting it. The code will only effect the first instance of the name "Brick" but if the code is being ran multiple times it may or may not choose the same brick if the order of the brick changes in the workspace.
Hope this helps