what is part.name?
example
function lightOnFire(part) print("Going to light this part on fire:") print(part.Name)
.Name tells you the name of the specified target such as a part. In this case, the script sample you put here tells us that a part will be set on fire and it prints the part's name.
.Name is mostly used for changing instance names such as:
Part = Instance.new("Part",workspace) Part.Name = "Brick"
Hope this helped!
Each object in roblox has something called a name which is a readable a writable string/text value that they can be called as. This can help for scripts finding certain children or descendants(Objects inside of another object) or to just be able to distinguish one part from another.
Below are all the different uses of the Name property.
If you use Part.Name
it can be used to change the object's name. For example: Part.Name = "Foo"
. Now if you find the part inside of your explorer tab, you'll find a brick that has the name "Foo".
Names could be used to get a certain child of an object: Model.Foo.BrickColor
(BrickColor is the color of a brick). In this example, we have a model and inside of the model we need to get a brick. We get it by doing Model.Foo
. Which means, "Inside of the Model, find the first object with the name of Foo exactly spelled that way," and you get the part.
Comparing strings are important. For example if you're trying to see if a certain character is a specific user. If you use an if then
statement, which is a chunk of code that only fires when the statement you insert is true: if 1+1 == 2 then
would run because 1+1 is 2. if 1+1 == 1 then
this will not run because 1+1 is never equal to 1. The statement is false. They also don't work if the statement is nil. if nil then
would never run. But if "string" then
would run because strings are not false and are not nil, but remember those 2 equal signs? They mean, "compare these 2 values and see if they're equal. I'll return true if the names match." if "Part" then
will always run but if we use our old part, "Foo" and compare them they'll be false. Because "Part" is not equal to "Foo". if "Part" == Model.Foo.Name then
won't run. We can use Model.Foo.Name
because name is a string or text value just like when a word is in parenthasis.
Hope it helps!
The name tells you what it is called in Explorer and what should be used in scripting. For example a script in a part
print("The name of this part is called "..script.Parent.Name.."!")
So if you named the part Bob then it would say "The name of this part is called Bob!" Or you can do if it is named something like
if script.Parent.Name == "Apple" then print("Yay!") end
Hope you understand!