Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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?

01local Frame = script.Parent
02local Buttons = game.Workspace.Buttons:GetChildren()
03local ClickDetector = -- i wanna get the clickdetector of many parts with the same name in a folder here
04local TweenS = game:GetService("TweenService")
05local Db = false
06local FadeTime = 3
07ClickDetector.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
16end)

2 answers

Log in to vote
1
Answered by 2 years ago

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

01local ClickDetectors = {}
02local Folder = workspace:WaitForChild('ClickDetectors')
03-- change this to the location of your folder
04 
05for __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
11end

fyi i have not personally tested this code myself

0
Alright thanks! I'll test it later! hellmet1 42 — 2y
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 42 — 2y
0
This is what i tried doing, look at the answers hellmet1 42 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
01local Frame = script.Parent
02local ClickDetectors = {}
03local Folder = workspace:WaitForChild('Buttons')
04local TweenS = game:GetService("TweenService")
05local Db = false
06local FadeTime = 3
07for __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()
View all 21 lines...
0
Consider changing __object.Mouseclick to __object.MouseClick (case sensitivity threw an error for me), other than that, the implementation looks fine loowa_yawn 383 — 2y
1
Thank you so so much dude! I've been trying to do fix this for many days! hellmet1 42 — 2y

Answer this question