Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Insert a ClickDetector in all ClassName = "Part"?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago
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

Log in to vote
2
Answered by 8 years ago

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

Ad

Answer this question