How can I make this script parent to a Frame inside a different ScreenGui

Hello! How can I parent this script to a Frame that is located inside a different ScreenGui? 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)

I still want to use that script, but how can I make it parent to this Frame inside “ExclusiveCodes”


(You click the ImageButton to open the frame, the LocalScript that I said above is the script to open the frame)

Any help will be appreciated! :slight_smile:

1 Like

Honestly, there’s no need to reparent, just set a variable that is that frame, and then you can use the script as if it were there, scripts parents, generally don’t matter. You can just run the same function, but instead of script.Parent, use a variable for the frame you want.

You could clone it and disable the old one (if needed)

I hardly know anything about code, so can you explain to me where I would put the thing/change?

Just put local Frame = script.Parent.Parent.Parent.Parent.Parent.ExclusiveCodes.Frame
at the front, and go from there.

At the front front? Like above everything?

Yes, it’s a variable so it would have to be there. Bens suggestion may also work though. Not to sure what you want to though! Considering it’s a frame and MouseButton1Down wouldn’t work on it!

Like this?

script.Parent.Parent.Parent.Parent.Parent.ExclusiveCodes.Frame
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)

You gotta set the variable!
make a variable by doing: local TestVariable = script.Parent.Parent.Parent.Parent.Parent.ExclusiveCodes.Frame
TestVariable.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)

1 Like

Again I don’t have any knowledge with scripting, do I don’t know what any of that is, plus you made it all weird so I don’t understand it.

1 Like

Like this???

local TestVariable = script.Parent.Parent.Parent.Parent.Parent.ExclusiveCodes.Frame
TestVariable.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)

Hello? Are you there? I am still confused

Hey, I remember you from another thread :slight_smile: It doesn’t matter which screen gui you want to parent to, it will ALWAYS be accessible from a local script.

I see in your code you haven’t done any reparenting.
You’ll have to add something like this:

script.Parent = TestVariable

Place it wherever you want, when it is parented depends on where you put it in the script :slight_smile: