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)
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