Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would you target a classname and delete it?

Hello guys my question is how would you target a classname and delete it

See what im trying to do is find a CharacterMesh aka Package like 2.0 3.0 and delete since it Conflicts with the game i cant use FindFirstChildOfClass Since it crashes roblox and is disabled

Is there a easier way to do it without FindFirstChildOfClass?

1 answer

✓ 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 -- Model you are looking for children in

for _, child in ipairs(model:GetChildren()) do
	if child:IsA("CharacterMesh") then
		child:Destroy()
	end
end

2 comments

0

thanks it worked i just need to understand for is for _, child in ipairs

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.