I’m trying to detect if one of any of the imagebuttons is pressed in my GUI, the only problem is I have zero clue of how to do that. But basically, I’m trying to make it so that one is pressed the rest fade out while the one pressed stays visible. And then a delay before the one clicked fades out. I do sort of have an idea on how to do that, but I know my way would be messy (write a line for each button that fades it out) plus I would have to do that for each button combination. I don’t really have any idea how to go about writing this though but here’s what I have so far:
local z = script.Parent.z
local x = script.Parent.x
local c = script.Parent.c
local v = script.Parent.v
local TweenService = game:GetService("TweenService")
local time = 3
local FadeOut = TweenService:Create(script.Parent.z, TweenInfo.new(time), {ImageTransparency = 0})
FadeOut:Play()
FadeOut.Completed:Wait()
local buttons = {
script.Parent.z;
script.Parent.x;
script.Parent.c;
script.Parent.v;
}
local TweenService = game:GetService("TweenService")
local pressed = false
local pressedButton
local t = 3 --Instead of time, since "time" is in the luau dictionary
for i,v in pairs(buttons)do
v.MouseButton1Click:Connect(function()
if pressed == false then
pressed = true
pressedButton = v
for i,v in pairs(buttons)do
if v ~= pressedButton then
local FadeOut = TweenService:Create(v, TweenInfo.new(t), {ImageTransparency = 0})
FadeOut:Play()
end
end
task.wait(t)
end
end)
end
local buttons = {
script.Parent.z;
script.Parent.x;
script.Parent.c;
script.Parent.v;
}
local TweenService = game:GetService("TweenService")
local time = 3
local pressed = false
local pressedButton
for i,v in pairs(buttons) do
v.MouseButton1Click:Connect(function()
pressedButton = v
pressed = true
for i,v in pairs(script.Parent:GetDescendants()) do
if v ~= pressedButton and v.Name ~= "LocalScript" then
local FadeOut = TweenService:Create(v, TweenInfo.new(time), {ImageTransparency = 1})
FadeOut:Play()
end
end
end)
end
I suppose I should have clarified this better in my description, basically, whatever button is pressed I want the rest of them to tween transparency, side note I’m getting an error of some sort on line 22
can we see the directory? because if there is anything other than the imagesbutton then you need to add it in the script on the first if (he other three should disappear all togeter right?)
local buttons = {
script.Parent.z;
script.Parent.x;
script.Parent.c;
script.Parent.v;
}
local TweenService = game:GetService("TweenService")
local t = 3
local pressed = false
local pressedButton
for i,v in pairs(buttons) do
v.MouseButton1Click:Connect(function()
if not pressed then
pressedButton = v
pressed = true
for i,v in pairs(script.Parent:GetDescendants()) do
if v ~= pressedButton and v.Name ~= "LocalScript" and v.Name ~= "Script2" and v.Name ~= "_ctext" and v.Name ~= "_vtext" and v.Name ~= "_xtext" and v.Name ~= "_ztext" then
local FadeOut = TweenService:Create(v, TweenInfo.new(t), {ImageTransparency = 1})
FadeOut:Play()
end
end
task.wait(t)
end
end)
end
if you want more things to not disappear then change this line
f v ~= pressedButton and v.Name ~= "LocalScript" and v.Name ~= "Script2" and v.Name ~= "_ctext" and v.Name ~= "_vtext" and v.Name ~= "_xtext" and v.Name ~= "_ztext" then
This is working for me, but how would I do the opposite for the text, as in making everything but the corresponding text disappear (i.e: _ztext and z when z is pressed)?