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

Don't understand something on the blog?

2 answers

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

1 comment

0

Cleared it up. Thanks

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