How might I get all the parts in a model? I have a bunch of scripts etc inside of a model and I am trying to get all the parts inside the model so I can alter the part's properties etc. Is there a way to get all the parts of a model?
✓ ANSWER ACCEPTED
How to get every part in a model?
3 answers
✓ Accepted answer
You can get all the parts inside a model or really any instance by using the :GetDescendants() function.
It would look something like this
local model = game.Workspace.Model --//If there is a model in workspace
for i, v in pairs(model:GetDescendants()) do
print(v.Name) --//Will print out the name of every descendant of the model
end
If you wanted to check just for parts/baseparts, you could do this
local model = game.Workspace.Model --//If there is a model in workspace
for i, v in pairs(model:GetDescendants()) do
if (v:IsA("BasePart")) then
--//The part we are currently on inside the loop is a part/basepart
end
end
Thanks, this is my script with yours but it is not working?
z = script.Parent
while true do
wait(1)
if z.Zombie.Health == 0 then
local charChildren = z:GetChildren()
--"char:GetChildren()" is a table containing all children in Character--
for i,v in pairs(charChildren) do
--"for loop" to run through objects in table--
if v:IsA"Part" then
-- "If Then Statement" to check if current Object is a Part--
print(v.Name .. " -- IS A PART")
-- printing "Object is a Part" if Object passes the Check
end
-- closes the "if then statement"
end
-- closes the "for loop"
end
end
1 comment
0
It should work correctly when the Zombie is dead
Use ":GetChildren()" on the model to get a table of all the children in the model and use an "If Then Statement" to check for parts; Example:
local plr = game.Players.LocalPlayer
local char = plr.Character
local charChildren = char:GetChildren()
--"char:GetChildren()" is a table containing all children in Character--
for i,v in pairs(charChildren) do
--"for loop" to run through objects in table--
if v:IsA"Part" then
-- "If Then Statement" to check if current Object is a Part--
print(v.Name .. " -- IS A PART")
-- printing "Object is a Part" if Object passes the Check
end
-- closes the "if then statement"
end
-- closes the "for loop"
1 comment
0
I tried changing it to suit me but it didn't work, my script is below
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
ahh ok thx