How to make UI Button script opens Frame in another ScreenGUI

Hello! I am trying to make this LocalScript that I have in my ImageButton open a frame in another ScreenGui. The LocalScript highlighted in the ImageButton in Codes, I want it to open the Frame inside “ExclusiveCodes”. I already have a script that I have been using which can open and close the GUI from pressing it twice. I wan’t to keep using this Script but make it open the frame in the different ScreenGui. I originallyhad it inside the Codes TextButton but changed it to a ScreenGui so I can make it position into the middle.

Here is the script:

script.Parent.MouseButton1Click:Connect(function()
	
	for _, v in pairs (script.Parent.Parent.Parent.Parent:GetChildren()) do
		if v:IsA("Frame") then
			for _, nV in pairs(v:GetChildren()) do
				if nV:IsA("TextButton") then
					for _, v2 in pairs(nV:GetChildren()) do
						if v2:IsA("Frame") then
							if v2 == script.Parent.Parent.Frame then
								v2.Visible = not v2.Visible
							else
								v2.Visible = false
							end
						end
					end
				end
			end
		end
	end

end)

Example Image:

1 Like
-- Local script for the button you want to use to open the different frame
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    player.PlayerGui.ExclusiveCodes.Frame.Visible = true
end)

Extremely simple, really.

2 Likes

Okay well the script I am using, makes it open and close if you press it twice. It lets you open it, or you can press the X to close it, or click the button again to close it

1 Like

So, you want a script that lets you open the UI with one click, and when you click it again the UI closes?

1 Like

Well I want to my script still, but it will let me open the frame inside the Gui that I am talking about. I never asked for a new script

Then what is the problem?

You said that your script already opens a Frame from another Screen Gui, so I don’t know what to help here.

No no, I want it to open the frame in the other GUI, did you even read the message I put above

Okay look, what I want help with is the script I included, I want it to open the frame inside the other Screen Gui. I never said it could already, I want it TO do that.

If you want it to open another frame just change the path (ex. script.Parent.Parent.ExampleFrame)

1 Like

What you’re doing right now is very complicated. I understand your perspective but you’re really making it hard for yourself. With this script it will be quite hard and complicated to make it so you can open it in another gui. Just like @ValiantWind said, change your script to something more simple:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    player.PlayerGui.ExclusiveCodes.Frame.Visible = not player.PlayerGui.ExclusiveCodes.Frame.Visible
end)

I understand if you want to use your own script but this is the best way to do it.

2 Likes

I stated I want to use my script, because it lets me open and close it. You can open it, click it again to close it, it also prevents multiple UI to show up. There is a reason why I want to use my script

But the frame is in a different ScreenGui?!

It doesn’t matter which ScreenGUI the Frame is in. Just change the path, and the Frame will open just like what @NeoGaming_RBLX said.

Where do I change the path?! That’s what I am asking

If the path is something like this:

script.Parent.Parent.Frame --I don't know what your path is, but it should be something like this
--it's easy to change the path to
script.Parent.Parent.Parent.OtherScreenGui.OtherFrame --Also should look something like this
2 Likes

Haha, i understand that, but this script does exactly the same, with better performance and much less complicated.

1 Like