Hey I'm trying to listen for all the clickdetector MouseClick event without doing all the functions manually because i have 100 parts to check. I'm trying to do this for my a* algorithm but I'm stuck.
local tab = {}
local closed = {}
local open = {}
for i,v in pairs(workspace:GetChildren()) do
if v.Name == 'Part' then
tab[#tab + 1] = v
Instance.new("ClickDetector", v)
end
end
math.randomseed(tick())
local r = math.random(1,#tab)
local startingPoint = tab[r]
startingPoint.BrickColor = BrickColor.new('Really red')
local cl = startingPoint:FindFirstChild('ClickDetector')
cl:Destroy()

1 comment
Thank you! I thought of this method but i didn't think the last for loop would would thank your pointing this out!