✓ Accepted answer
This is quite easy to emulate. All you need to do is search through the objects until an object with a given ClassName is found:
local function FindFirstChildOfClass(instance, className)
for _, child in ipairs(instance:GetChildren()) do
if child:IsA(className) then
return child
end
end
return nil
end
There is one subtlety however in that it will also find things that inherit from that particular ClassName, which sometimes (and in the general case of this function) isn't desired.
In your case, it seems as though you want to remove all instances of CharacterMesh inside the character. This can be done in a similar manor to this function without having to call the function multiple times:
local model
for _, child in ipairs(model:GetChildren()) do
if child:IsA("CharacterMesh") then
child:Destroy()
end
end
2 comments
thanks it worked i just need to understand for is for _, child in ipairs
It's a genaric for loop. It uses the iterator function ipairs to retrieve key/value pairs from a table. In this case, '_' gets set to the key and 'child' gets set to the value. It does this for each pair in the table. Check out this wiki article for more information: http://wiki.roblox.com/index.php?title=Table#Iteration