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 local FadeTime = 3 ClickDetector.MouseClick:Connect(function() if not Db then Db = true TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 0}):Play() task.wait(FadeTime) TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 1}):Play() task.wait(FadeTime) Db = false end end)
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
local Frame = script.Parent local ClickDetectors = {} local Folder = workspace:WaitForChild('Buttons') local TweenS = game:GetService("TweenService") local Db = false local FadeTime = 3 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() task.wait(FadeTime) TweenS:Create(Frame,TweenInfo.new(0.5),{BackgroundTransparency = 1}):Play() task.wait(FadeTime) Db = false end end) end end