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
✓ ANSWER ACCEPTED
Insert a ClickDetector in all ClassName = "Part"?
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.
