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

Don't understand something on the blog?

Asked by 9 years ago

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

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago
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.

Ad
Log in to vote
-1
Answered by 9 years ago

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

0
Cleared it up. Thanks WolfgangVonPrinz 0 — 9y

Answer this question