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

How to make script work for all ImageButtons inside of a GUI?

Asked by 7 years ago
Edited 7 years ago

How would making this work for ALL ImageButtons in a GUI work? I'd like to have one main script instead of having to copy and paste it inside of all the ImageButtons. It clones a ParticleEmitter and Sound from inside of the Script and removes them after some time when the ImageButton is clicked.

Not too sure how I'd go about laying it out or if I'm doing it right.

for i,c in pairs(GetChildren()) do
    if c:IsA'ImageButton' then
    c.MouseButton1Click:connect(function()
function onClicked()
    local particle = script.ParticleEmitter:Clone()
    game:GetService("Debris"):AddItem(particle, .35)
    particle.Parent=Character.Torso
    particle.Enabled = true

    wait(.35)
    local sound = script.TransformSound:Clone()
    game:GetService("Debris"):AddItem(sound, 3)
    sound.Parent = Character
    sound:Play()
    wait(3)

end 
script.Parent.MouseButton1Click:connect(onClicked)

1 answer

Log in to vote
0
Answered by
Etheroit 178
7 years ago
Edited 7 years ago

This script should work You binded same function two times I mean You did something like this OnClicked > OnClicked > Function This should work

local Character = game.Players.LocalPlayer.Character
function check(holder)
for i,c in pairs(holder:GetChildren()) do
    if c:IsA'ImageButton' then
        c.MouseButton1Click:connect(function()
             local particle = script.ParticleEmitter:Clone()
             game:GetService("Debris"):AddItem(particle, .35)
             particle.Parent=Character.Torso
             particle.Enabled = true

             wait(.35)
             local sound = script.TransformSound:Clone()
             game:GetService("Debris"):AddItem(sound, 3)
             sound.Parent = Character
             sound:Play()
             wait(3)
        end)
    end
end 
end
for _, i in pairs(script.Parent:GetChildren()) do
 if string.upper(string.sub(i.Name, 1, 1)) == "C" then
  check(i)
 end
end
for _, i in pairs(script.Parent.Parent:GetChildren()) do
 if string.upper(string.sub(i.Name, 1, 1)) == "C" then
  check(i)
 end
end

Updated script This should be placed in LocalScript

0
I have the hierarchy like this: AlbedoGUI - Main - C1, I'd like for it to check through any page beginning with C. I tried this: local holder = script.Parent['C'] but not sure if it's correct. Also, it says "Unknown global Character" LuckyAura -1 — 7y
0
The GUI is inside of the ReplicatedStorage, and is taken from there when a tool is used. LuckyAura -1 — 7y
0
At the start add local Character = game.Players.LocalPlayer.Character Etheroit 178 — 7y
0
also script might be LocalScript so it will work (about this ['C'] You did this alright) Etheroit 178 — 7y
View all comments (14 more)
0
Updated script. It should work now. I didnt know that there isnt definied Character variable. Sorry Etheroit 178 — 7y
0
defined* Etheroit 178 — 7y
0
It says that C is not a valid member of Frame LuckyAura -1 — 7y
0
are You sure that There is also C thing in Parent of script ( are u sure that there is a thing named C in the same place where script is held)? Etheroit 178 — 7y
0
I have many Frames (pages of GUI) named like C1, C2. The script is inside of a Frame called Main inside of AlbedoGUI. LuckyAura -1 — 7y
0
and is C frame in Main frame too? Etheroit 178 — 7y
0
if no then set location to script.Parent.Parent["FULL NAME OF FRAME WHERE ARE IMAGEBUTTONS"] Etheroit 178 — 7y
0
change this FULL NAME... to the full name of the C frame Etheroit 178 — 7y
0
There's no frame named just C, I'd like it to check for any frames with C at the beginning, like the frames C1 and C2, not sure how to do it. LuckyAura -1 — 7y
0
Oh so there are placed in the gui? and in these frames are imagebuttons Alright let me update script Etheroit 178 — 7y
0
here You go. it might work now Etheroit 178 — 7y
0
Thanks a bunch for your help, I really appreciate it a lot. Does the bottom part need to be there twice because it seems to work with it there just once? LuckyAura -1 — 7y
0
uhh keep it :) just for making sire that works. If its possible then I appreciate if You click "Accept answer" so dat will be nice :) thank You at all Etheroit 178 — 7y
0
Thank You very much Etheroit 178 — 7y
Ad

Answer this question