0

# How do i select the clickdetector of many buttons in a folder?

So, I am making an elevator that has a fading gui when you click a button, just to clarify, this script isn't mine, but how do i get the clickdetector of every part in the folder?

local Frame = script.Parent
local Buttons = game.Workspace.Buttons:GetChildren()
local ClickDetector = -- i wanna get the clickdetector of many parts with the same name in a folder here
local TweenS = game:GetService("TweenService")
local Db = false
ClickDetector.MouseClick:Connect(function()
if not Db then
Db = true
TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 0}):Play()
TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 1}):Play()
Db = false
end
end)


1

If you are looking to get every click detector inside a given folder (either as a child of a child, child of a child of a child, etc..):

you can use GetDescendants() and IsA(), both respectfully getting every object inside an object, and checking if a Roblox object is a specific type

local ClickDetectors = {}
local Folder = workspace:WaitForChild('ClickDetectors')
-- change this to the location of your folder

for __index, __object in ipairs(Folder:GetDescendants()) do
if __object:IsA('ClickDetector') then
table.insert(ClickDetectors, __object)
-- or do something with '__object'
-- as it is confirmed to be a clickdetector
end
end



fyi i have not personally tested this code myself

0
Alright thanks! I'll test it later! hellmet1 40 — 12d
0
Dont really get how i should put this in my script, sorry I'm a beginner. could you copy it and put it in it? hellmet1 40 — 11d
0
This is what i tried doing, look at the answers hellmet1 40 — 11d
0
local Frame = script.Parent
local ClickDetectors = {}
local Folder = workspace:WaitForChild('Buttons')
local TweenS = game:GetService("TweenService")
local Db = false
for __index, __object in ipairs(Folder:GetDescendants()) do
if __object:IsA('ClickDetector') then
table.insert(ClickDetectors, __object)
__object.Mouseclick:Connect(function()
if not Db then
Db = true
TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 0}):Play()
TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 1}):Play()