How would one make a for loop for Clickdetectors that can distinguish which instance or if there any better way to distinguish which clickdetector is being clicked.
The script I will provide will not contain the logic I use for my placement system.
How do I know the clickdetector can’t distinguish?
Because when I put my script logic and if lets say there was 3 of the same instances with same children then the script cannot distinguish which one I’m clicking and is picking up the one that I did not click, Video is provided.
this is the current script I’m using:
for _, EditablePlacement in pairs(Placed_Objects:GetChildren()) do
local ClickDetector = EditablePlacement:FindFirstChild("ClickDetector")
-- Check if ClickDetector exists in the current object
if ClickDetector then
ClickDetector.MouseClick:Connect(function(Player)
print("Clicked on", EditablePlacement.Name)
-- without logic
end)
end
end
Try using getDescendants(), cause from what I can tell, it seems like your script isnt recognizing all the click detectors. I would also use task.spawn() and FindFirstChildOfClass().
for _, EditablePlacement in pairs(Placed_Objects:GetDescendants()) do
local ClickDetector = EditablePlacement:FindFirstChildOfClass("ClickDetector")
-- Check if ClickDetector exists in the current object
if ClickDetector then
task.spawn(function()
ClickDetector.MouseClick:Connect(function(Player)
print("Clicked on", EditablePlacement.Name)
-- without logic
end)
end)
end
end