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

Problem with searching though the Workspace (IsA:("Part"))?

I am trying to remove all parts of a certain colour, but the script is not working. This is the script (Normal script in the workspace):

function Colour_Delete(Colour)
	for index, child in pairs(workspace:GetChildren()) do
		if child.ClassName:IsA("Part") then
			if child.BrickColor == Colour then
				child:remove()
				print (child.."Removed")
				wait(.1)
			end
		end
	end
end

Colour_Delete("Dark stone grey")

This is the output:

19:32:12.579 - Workspace.Side_Stoning:3: attempt to call method 'IsA' (a nil value) 19:32:12.580 - Stack Begin 19:32:12.581 - Script 'Workspace.Side_Stoning', Line 3 - global Colour_Delete 19:32:12.581 - Script 'Workspace.Side_Stoning', Line 13 19:32:12.582 - Stack End

2 answers

✓ Accepted answer

As your output suggests, their is a simple mistake that you made. Try this:

function Colour_Delete(Colour)
	for index, child in pairs(workspace:GetChildren()) do
		if child:IsA("Part") then --You don't need to use "ClassName"
			if child.BrickColor == Colour then
				child:remove()
				print (child.."Removed")
				wait(.1)
			end
		end
	end
end

Colour_Delete("Dark stone grey")

I think that this should work now. If not, leave a comment below, and I'll look through again to see if I missed anything. Hope I helped :P

To elaborate, the IsA is a method on instances, yet you tried to call it on a property. This is why you get the error. Dyler's code should work.


However, it would also be a good idea to combine the if statements.

if child:IsA("Part") and child.BrickColor == Colour then

This may look scary to you. After all, if the child isn't a Part, then it won't have a BrickColor. However, computers are lazy and it won't bother checking the second condition if the first one is found to be false.


You may want wedges, corner wedges, and unions to also be deleted. In this case, check if they're BaseParts. All part objects are inside a higher BasePart class, so checking it that way will allow for wedges and such.

child:IsA("BasePart")

2 comments

0

Thanks, however, unions and negate parts aren't under the BasePart, upvoted.

0

Really? They should be.

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