Script.parent.parent.parent going way further then it can?

My localscript button code is:

script.Parent.MouseButton1Down:Connect(function()
for i,v in pairs(game:GetChildren(script.Parent.Parent.Parent) do
print(v)
if v.Name ~= “Selection” or “Dragify” or “UICorner” then
v.Visible = false
end
end
script.Parent.Parent.Parent.Home.Visible = true
end)

This is how the whole list looks like:


This code should make the Home frame appear if it has been pressed and other frames dissapear.
Please reply here if you have a solution thanks.

1 Like
script.Parent.MouseButton1Down:Connect(function()
	for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
		print(v)
		if v.Name ~= "Selection" or v.Name ~= "Dragify" or v.Name ~= "UICorner" then
			v.Visible = false
		end
		script.Parent.Parent.Parent.Home.Visible = true
	end
end)

Make sure to indent next time.

1 Like

Thank you, and sorry for the silly error I made.

1 Like

Don’t worry, I’m glad that I could help!

1 Like

From what I can understand, You’re trying to set visible to true the Home frame once the homeButton is clicked and others set to false. so here’s what I did.

local UI_ScreenGui = script:FindFirstAncestorWhichIsA("ScreenGui") -- Why? Since there's only one main ancestor tht is a ScreenGui class.
local Main = UI_ScreenGui:WaitForChild("Main")

local thisButton = script.Parent -- The button

thisButton.MouseButton1Down:Connect(function()
   for _, children in pairs(Main:GetChildren()) do
       if children:IsA("Frame") and children.Name == "Home" then
         children.Visible = true
         break --// End the loop since it found the subject.
       elseif children:IsA("Frame") and children.Name ~= "Home" then
         children.Visible = false --// No break loops to prevent stopping the loop and other frames are still visible.
       end
   end
end)
1 Like