what i want is after these click detectors are generated i want them to be linked to that clicked() function but when i click them nothing prints out i know i can use collection service but i want to know if i can do it like this ?
function Clicked()
print('clicked')
end
local function GetDetectors()
for i , v in pairs(GreenParts) do
local clickdetector = Instance.new("ClickDetector")
count += 1
clickdetectors[count] = clickdetector
clickdetector.Name = ('clickdetector'.. count )
clickdetector.Parent = v
clickdetector.MouseClick:Connect(Clicked)
end
count = 0
end
local function GetDetectors()
for i , v in pairs(GreenParts) do
local clickdetector = Instance.new(âClickDetectorâ)
count += 1
clickdetectors[count] = clickdetector
clickdetector.Name = (âclickdetectorâ⌠count )
clickdetector.Parent = v
clickdetectors[count].MouseClick:Connect(Clicked)
end
function Clicked()
print(âclickedâ)
end
local function GetDetectors()
for i , v in pairs(GreenParts) do
local clickdetector = Instance.new(âClickDetectorâ)
count += 1
clickdetectors[count] = clickdetector
clickdetector.Name = (âclickdetectorâ⌠count )
clickdetector.Parent = v
clickdetectors[count].MouseClick:Connect(Clicked)
end
count = 0
end
You donât need variable count, in fact you have index in a for loop.
why youâd put click detector into array and do thought the it signal connection?
have you make sure click detector exist? Have you tried debugging? Is console clear?
I made a working code snippet here, match it to yours workflow⌠The code is working
Basically I tried to understand what you want to achieve and this is the right way to do so
local greenParts: Folder = workspace.greenParts
local clickDetectorsArr: {} = {}
local function onClick()
print("I was clicked")
end
local function initializeDetectors()
for index, part in pairs(greenParts:GetChildren()) do
local clickDetector = Instance.new("ClickDetector")
clickDetector.Name = string.format("Click_detector %i", index)
clickDetector.Parent = part
clickDetector.MouseClick:Connect(onClick)
clickDetectorsArr[clickDetector.Name] = clickDetector;
end
end
initializeDetectors()
first greenparts is just a table and im copying that table to use the number of instances inside it to run the loop as many as instances inside that table so u can say it is useless right now
and i tried to create 6 different part inside a model and do the same thing but generateing click detectors before the game starts and it works
xDD this is the same response i got from bing ai i find it funny sorry im trying to be rude i just find it funny anyways either count = count +1 or count += 1 are the same u can try it and besides if this doesnât work i would get an error instanatly when i run the script
well i found the issue
the problem was i had a ray cast that fires whenever i click on my mouse so if i click on that click detector it will get deleted before the clickdetector instance work