'Why is property "Name" in Roblox doesn't exist as "Name" like "ClassName" in code
I saw code example in Roblox api and class "Name" wasn't used as "Name" in code like "ClassName" do. Can you tell me the reason?
example: (ClassName code)
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.ClassName == "Part" then
print("Found a Part")
-- will find Parts in model, but NOT TrussParts, WedgeParts, etc
end
end
(Name code)
local baseplate = workspace.Baseplate
local baseplate = workspace["Baseplate"]
local baseplate = workspace:FindFirstChild("BasePlate")
Solution 1:[1]
Alright, so a ClassName is basically like a 'Type' if that makes sense. Name is to narrow down the actual NAME of the part. So lets say I have a workspace directory that looks like this:
Workspace:
CoolPart
AnotherPart
If I do:
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.ClassName == "Part" then
print("Found a Part")
end
end
It will print 'Found a Part' twice, because both CoolPart and AnotherPart are a Part (not a truss, not a wedge, an actual brick part) of the workspace, but if you do:
for _, child in ipairs(game.Workspace:GetChildren()) do
if child.Name == "Part" then
print("Found a Part")
end
end
It won't print anything, because of everything that is in workspace, none of them are actually titled 'Part', you get what I mean?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
