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

Insert a ClickDetector in all ClassName = "Part"?

for i,v in pairs (game.Workspace:GetChildren()) do
	if v.ClassName == ("Part") then
		print 'hey' --Does print
		Instance.new("ClickDetector") --Right here, I am trying to insert a ClickDetector in all Parts
	end
end

1 answer

✓ Accepted answer

Looks like you did not specify the parent of the new ClickDetectors, look below!

for index, child in pairs(workspace:GetChildren()) do
	if child.ClassName == "Part" then
		print(child.Name .. " is a Part!") -- optional line
		local ClickDetector = Instance.new("ClickDetector")
		ClickDetector.Parent = child
	end
end

The code above would create ClickDetectors in each of the parts in Workspace

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