Essentially, I am working on a script that will allow me to iterate through the children of a selected model, find the TextureIDs of said children (assuming they are MeshParts), and printing it into Studio’s built-in output (the script in question is executed in the command line.)
I’ve run into a major roadblock though: I don’t know how I would go about iterating through EVERY part found in the model. I’ve attached my script below. Help would be much appreciated!
I am rather new to Roblox Lua, so please don’t be too harsh.
for _, selectedObj in next, game.Selection:Get() do
if selectedObj:IsA("Model") then
local children = selectedObj:GetChildren()
if children[1]:IsA("MeshPart") then
print(selectedObj, "Children have been found! It IS a MeshPart.", children[1].TextureID, "\n")
else
print(print(selectedObj, "Children have been found! It is NOT a MeshPart.", children[1].Name, "\n"))
end
else
print("Fail!")
end
end
No. The script should ideally first compare one of the model’s children (in this case, a MeshPart) to the the condition if children[1]:IsA("MeshPart"). If it is true, it should then output the TextureID of said MeshPart. It should do this for EVERY part in the model.
Hmm, I’m a little confused on what you mean… However is this what you are looking for?
for _, selectedObj in next, game.Selection:Get() do
if selectedObj:IsA("Model") then
local children = selectedObj:GetChildren()
for _,Child:Instance in children do
if Child then
if Child:IsA("MeshPart") then
print(selectedObj, "Children have been found! It IS a MeshPart.", Child.TextureID, "\n")
else
print(selectedObj, "Children have been found! It is NOT a MeshPart.", Child.Name, "\n")
end
end
end
else
print("Fail!")
end
end
I’ve slightly modified your script to iterate through the ‘children’ table, instead of just checking the numeric key value of [1]
Well, this code only works for children of the selected model, not any descendants(children of children)
Here’s a slightly modified version that you may want in the future
for _, selectedObj in next, game.Selection:Get() do
if selectedObj:IsA("Model") then
local children = selectedObj:GetDescendants()
for _,Child:Instance in children do
if Child then
if Child:IsA("MeshPart") then
print(selectedObj, "Children have been found! It IS a MeshPart.", Child.TextureID, "\n")
else
print(selectedObj, "Children have been found! It is NOT a MeshPart.", Child.Name, "\n")
end
end
end
else
print("Fail!")
end
end