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?
01 | local Frame = script.Parent |
02 | local Buttons = game.Workspace.Buttons:GetChildren() |
03 | local ClickDetector = -- i wanna get the clickdetector of many parts with the same name in a folder here |
04 | local TweenS = game:GetService( "TweenService" ) |
05 | local Db = false |
06 | local FadeTime = 3 |
07 | ClickDetector.MouseClick:Connect( function () |
08 | if not Db then |
09 | Db = true |
10 | TweenS:Create(Frame,TweenInfo.new( 0.5 ), { BackgroundTransparency = 0 } ):Play() |
11 | task.wait(FadeTime) |
12 | TweenS:Create(Frame,TweenInfo.new( 0.5 ), { BackgroundTransparency = 1 } ):Play() |
13 | task.wait(FadeTime) |
14 | Db = false |
15 | end |
16 | 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
01 | local ClickDetectors = { } |
02 | local Folder = workspace:WaitForChild( 'ClickDetectors' ) |
03 | -- change this to the location of your folder |
04 |
05 | for __index, __object in ipairs (Folder:GetDescendants()) do |
06 | if __object:IsA( 'ClickDetector' ) then |
07 | table.insert(ClickDetectors, __object) |
08 | -- or do something with '__object' |
09 | -- as it is confirmed to be a clickdetector |
10 | end |
11 | end |
fyi i have not personally tested this code myself
01 | local Frame = script.Parent |
02 | local ClickDetectors = { } |
03 | local Folder = workspace:WaitForChild( 'Buttons' ) |
04 | local TweenS = game:GetService( "TweenService" ) |
05 | local Db = false |
06 | local FadeTime = 3 |
07 | for __index, __object in ipairs (Folder:GetDescendants()) do |
08 | if __object:IsA( 'ClickDetector' ) then |
09 | table.insert(ClickDetectors, __object) |
10 | __object.Mouseclick:Connect( function () |
11 | if not Db then |
12 | Db = true |
13 | TweenS:Create(Frame,TweenInfo.new( 0.5 ), { BackgroundTransparency = 0 } ):Play() |
14 | task.wait(FadeTime) |
15 | TweenS:Create(Frame,TweenInfo.new( 0.5 ), { BackgroundTransparency = 1 } ):Play() |