Values Help - GUI

Hello there - so basically I’m trying to make a GUI thing so when you select one button it displays a GUI pop up and when you select another it hides the first GUI pop up and displays its own GUI pop up.

First Local Script:

local object2 = script.parent.parent.Secondary.Frame
local clicked  = script.parent.parent.parent.Values.Primary.Value
local clicked2 = script.parent.parent.parent.Values.Secondary.Value
local sound = script.parent.parent.clicknoise

script.Parent.MouseButton1Click:Connect(function()
	sound:Play()
	if clicked == false and clicked2 == false then
		clicked = true
		print(clicked)
		object.Visible = true
		object:TweenSize(UDim2.new(0, 130,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
	else
		clicked = false
		--object:TweenPosition(UDim2.new(0.583, 0, 0, 0),1, Enum.EasingStyle.Quart)
		object:TweenSize(UDim2.new(0, 0,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
		wait (0.1)
		object.Visible = false
		print(clicked)
	end
end)

	
--script.parent.Visible = false
--script.parent.Selectable = false
--script.parent.parent.Close.Visible = true
--script.parent.parent.Close.Selectable = true```

**Second Local Script:**
```local object = script.parent.Frame
local object2 = script.parent.parent.Secondary.Frame
local clicked  = script.parent.parent.parent.Values.Secondary.Value
local clicked2 = script.parent.parent.parent.Values.Primary.Value
local sound = script.parent.parent.clicknoise

script.Parent.MouseButton1Click:Connect(function()
	sound:Play()
	if clicked == false and clicked2 == false then
		clicked = true
		print(clicked)
		object.Visible = true
		object:TweenSize(UDim2.new(0, 130,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
	else
		clicked = false
		--object:TweenPosition(UDim2.new(0.583, 0, 0, 0),1, Enum.EasingStyle.Quart)
		object:TweenSize(UDim2.new(0, 0,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
		wait (0.1)
		object.Visible = false
		print(clicked)
	end
	end)

--script.parent.Visible = false
--script.parent.Selectable = false
--script.parent.parent.Close.Visible = true
--script.parent.parent.Close.Selectable = true

Hierarchy:

However, I’ve found that when and do if clicked == false and clicked2 == false then if one is false then it just bypasses the other check.

Any ideas why?

2 Likes

You could have a single local script do the whole thing to avoid code repetition and possibly simplify things.

Edit: I have now added the button and frame references. The script should be able to be placed anywhere local scripts can run, unless the screengui has ResetOnSpawn set to true in which case the local script should be inside screengui or StarterCharacterScripts

local Players = game:GetService("Players")

local plr = Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")

local screenGui = plrGui:WaitForChild("ScreenGui")
local mainFrame = screenGui:WaitForChild("MainFrame")


local buttons = {
    mainFrame:WaitForChild("Primary"),
    mainFrame:WaitForChild("Secondary")
}

local frames = {
    buttons[1]:WaitForChild("Frame"),
    buttons[2]:WaitForChild("Frame")
}


local function hideFrame(frame)
    frame:TweenSize(UDim2.new(0, 0,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
    wait (0.1)
    frame.Visible = false
end

local function showFrame(frame)
    frame.Visible = true
    frame:TweenSize(UDim2.new(0, 130,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
end

for i, button in ipairs(buttons) do
    button.MouseButton1Click:Connect(function()
        local frame = frames[i]
        if frame.Visible then
            hideFrame(frame)
            return
        end
        -- the rest is only done if the frame wasn't visible
        for _, frame2 in ipairs(frames) do
            if frame2 ~= frame then
                hideFrame(frame2)
            end
        end
        showFrame(frame)
    end
end

How would I add the buttons/frames into that?

local buttons = {
	script.parent.Primary
	script.parent.Secondary
}

local frames = {
	script.parent.Primary.Frame
	script.parent.Secondary.Frame
}


local function hideFrame(frame)
	frame:TweenSize(UDim2.new(0, 0,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
	wait (0.1)
	frame.Visible = false
end

local function showFrame(frame)
	frame.Visible = true
	frame:TweenSize(UDim2.new(0, 130,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
end

for i, button in ipairs(buttons) do
	button.MouseButton1Click:Connect(function()
		local frame = frames[i]
		if frame.Visible then
			hideFrame(frame)
			return
		end
		-- the rest is only done if the frame wasn't visible
		for _, frame2 in ipairs(frames) do
			if frame2 ~= frame then
				hideFrame(frame2)
			end
		end
		showFrame(frame)
	end
end

This doesn’t seem to work

image

local button  = script.parent.Primary
local button2 = script.parent.Secondary

local buttons = {
	["Button"] = script.parent.Primary,
	["Button2"] = script.parent.Secondary
}

local frames = {
	["frame"] = script.parent.Primary.Frame,
	["frame2"] = script.parent.Secondary.Frame
}


local function hideFrame(frame)
	frame:TweenSize(UDim2.new(0, 0,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
	wait (0.1)
	frame.Visible = false
end

local function showFrame(frame)
	frame.Visible = true
	frame:TweenSize(UDim2.new(0, 130,0, 337), nil, Enum.EasingStyle.Linear, 0.1)
end

for i, button in ipairs(buttons) do
	button.MouseButton1Click:Connect(function()
		local frame = frames[i]
		if frame.Visible then
			hideFrame(frame)
			return
		end
		-- the rest is only done if the frame wasn't visible
		for _, frame2 in ipairs(frames) do
			if frame2 ~= frame then
				hideFrame(frame2)
			end
		end
		showFrame(frame)
	end)
end

Changed it to this but still doesn’t work - no error message

I have edited my earlier reply with some additions to the code.

You are a saint, thank you so much for coming back and replying instead of just leaving me haha.

1 Like