Detect if one of multiple imagebuttons are pressed

Can you rephrase that, I don’t understand the problem.

yours didn’t work so i tried to make it work

Ok so right now when I press a certain button (z for example) all the other buttons do their tweening effect as they should, the problem is I also want the text that is next to them to tween transparency as well.

Can you send me a screenshot of the explorer so I can see how this is layed out?

Also could you send me a screenshot of the GUI so I know exactly what you are talking about?

I figured it would be easier for you to use the GUI file I posted, but sure.


local buttons = {
	script.Parent.z;
	script.Parent.x;
	script.Parent.c;
	script.Parent.v;
}

local texts = {
	script.Parent._ztext;
	script.Parent._xtext;
	script.Parent._ctext;
	script.Parent._vtext;
}


local TweenService = game:GetService("TweenService")
local t = 3

local pressed = false
local pressedButton
local text

for i,v in pairs(buttons) do
	v.MouseButton1Click:Connect(function()
if not pressed then		
			pressedButton = v
			text = "_"..v.Name.."text"
		pressed = true
	for i,v in pairs(buttons) do
				if v ~= pressedButton then
			
					local FadeOut = TweenService:Create(v, TweenInfo.new(t), {ImageTransparency = 1})

					FadeOut:Play()
end
			end
			for i,v in pairs(texts) do
			if v.Name ~= text then
					local FadeOut1 = TweenService:Create(v, TweenInfo.new(t), {TextTransparency = 1})

				FadeOut1:Play()
				end
			end
			
		end
		task.wait(t)
end)
end

Uploading: image.png…
image

this should make the other texts invisible

sorry i actually gotta head out for now - cya

Alright so this is pretty much everything, the final thing I’m still trying to figure out is how to make it so that the one selected then slowly fades out after it. I’m basically trying to make the button clicked do something like this where the one selected slow fades out after the rest:
ezgif-2-621ef0108b

It’s fine, the fact that you were willing to try and help at all is enough for me.


local buttons = {
	script.Parent.z;
	script.Parent.x;
	script.Parent.c;
	script.Parent.v;
}

local texts = {
	script.Parent._ztext;
	script.Parent._xtext;
	script.Parent._ctext;
	script.Parent._vtext;
}


local TweenService = game:GetService("TweenService")
local t = 3

local pressed = false
local pressedButton
local text

for i,v in pairs(buttons) do
	v.MouseButton1Click:Connect(function()
if not pressed then		
			pressedButton = v
			text = "_"..v.Name.."text"
		pressed = true
	for i,v in pairs(buttons) do
				if v ~= pressedButton then
			
					local FadeOut = TweenService:Create(v, TweenInfo.new(t), {ImageTransparency = 1})

					FadeOut:Play()
end
			end
			for i,v in pairs(texts) do
				if v.Name ~= text then
					local FadeOut1 = TweenService:Create(v, TweenInfo.new(t), {TextTransparency = 1})

					FadeOut1:Play()
				end
			end
			
			for i,v in pairs(script.Parent:GetDescendants()) do
			if v.Name == "_"..pressedButton.Name.."text" then
				print(v.Name)
				local FadeOut2 = TweenService:Create(pressedButton, TweenInfo.new(t), {ImageTransparency = 1})
					local FadeOut3 = TweenService:Create(v, TweenInfo.new(t), {TextTransparency = 1})
					wait(3.5)
				FadeOut3:Play()
			FadeOut2:Play()
			end
			end
			end
		task.wait(t)
end)
end

1 Like

to change the time change this line

wait(3.5)

Use task.wait(), because the regular wait is deprecated.