Make only 1 image visible when last checked image was visible (hard to explain)

Aim

Make a menu where when you click another box, the previous tick is set to invisble and the one you clicked is set to visible (it is very hard to explain)

Code

As of now, this is my code:

local mainFrame = script.Parent.Parent.Parent.Parent

local settingsGUI = mainFrame.MainFrameSettings
local menuGUI = mainFrame.Menu

local positions = {
	Left = UDim2.new(1, 0, 0, 0),
	Middle = UDim2.new(0, 0, 0, 0),
	Right = UDim2.new(-1, 0, 0, 0),
}

local graphicsFolder = settingsGUI.Graphics
local lightingFolder = settingsGUI.Lighting
local musicFolder = settingsGUI.Music

local activated = false
local debounce = false

-- Settings

script.Parent.Parent.SettingsButton.MouseButton1Click:Connect(function()
	menuGUI:TweenPosition(positions.Right)
	wait(0.8)
	settingsGUI:TweenPosition(positions.Middle)
end)

for _, setting in pairs(graphicsFolder:GetChildren()) do
	if setting.ClassName == "ImageButton" then
		setting.MouseButton1Click:Connect(function()
			local usingValue = setting:FindFirstChild("Using").Value
			setting.MouseButton1Click:Connect(function()
				if usingValue == false then
					print("false")
					setting:FindFirstChild("SettingBeingUsed").ImageTransparency = 0
				else
					print("true")
					setting:FindFirstChild("SettingBeingUsed").ImageTransparency = 1
				end
			end)
		end)
	end
end

Image

[The comment attached makes it make alot more sense!]

So basically, I want it where when you click Low, the tick on High is set to invisible and the tick on Low is set to true.

Once clicked you can loop through the All buttons and do

for i , v in pairs(graphicsFolder:GetChildren()) do
 if v ~= setting then -- Checkings if its not the One we clicked
  local Image = v:FindFirstChildOflClass("ImageLabel") -- Finds First Child of Class Image Label
 Image.Visible = false 
 end

I got to go , so thats all I can give hope this helps !

No I mean if I clicked Low (say High was clicked before), Low’s tick would become visible and High’s tick should become invisible, if you get me?

Also I can sense some memory leak , you creating a new MouseButton1Click event for the Button once you click , basically a nested event. Why are you doing that?

Because how else am I ment to use MouseButton1Click?

You can shorten your script to something like this.

for _, setting in pairs(graphicsFolder:GetChildren()) do
	if setting:IsA("ImageButton") then
		setting.MouseButton1Click:Connect(function()
			local usingValue = setting:FindFirstChild("Using").Value
			if usingValue == false then
				print("false")
				setting:FindFirstChild("SettingBeingUsed").ImageTransparency = 0
			else
				print("true")
				setting:FindFirstChild("SettingBeingUsed").ImageTransparency = 1
			end
            for i , v in pairs(graphicsFolder:GetChildren()) do
                 if v ~= setting then -- Checkings if its not the One we clicked
                    local Image = v:FindFirstChildOflClass("ImageLabel") -- Finds First Child of Class Image Label
                     Image.Visible = false 
                 end
            end
		end)
	end
end

How would that change anything though??

Oh and I made a new script that works…

for _, setting in pairs(graphicsFolder:GetChildren()) do
	if setting.ClassName == "ImageButton" then
		setting.MouseButton1Click:Connect(function()
			local descendants = setting.Parent:GetDescendants()
			
			for _, image in pairs(descendants) do
				if image.Name == "GraphicSetting" then
					image.Parent = setting
				end
			end
		end)
	end
end

Well if thats what you want to do , you can do that.

1 Like

Removes Memory leakage and does the thing you wanted to do.

EDIT : I don’t know about your GUI Hierarchy , so I can’t guarantee it to work

Just for knowledge, what’s a memory leak? I genually don’t know.

Oh it worked. Surprisingly it was that simple.

Memory leaks are some stuffs in memory those are cleaned up , for example in your script when you click the Button you are creating one more setting.MouseButton1Click:Connect(function() , doing this will create a connect for MouseButton1Click in the memory and each time you click more and more of the Connection will be created and they exist in memory .

For more info : Garbage Collection and Memory Leaks in Roblox - What you should know

Thats nice to know . If my posts helped you , please mark it a s solution.

1 Like

Umm sorry to interrupt you , but you marked you question as the solution , it would be only helpful for me if you mark my answer as the solution @GamingExpert0312

Alright then fine, I’ll mark your answer as a solution.

1 Like