How to detect if a GUI is in a specific spot?

hello! i want it so that whenever a player opens a gui, any other gui opened goes away. However, to do this I want to make it so that it detects when it is in a certain spot on the screen.

I have no idea how to do this though, and any ideas or help would be appreciated! I’ve looked on devforum and found nothing relating to this topic.

Thank you.

2 Likes

I wouldn’t do it this way. It could technically work. But a better method would be to make it when you open a ui that would cause others to close, have it send a message to the others so they know to close themselves.

For example, fire a remote event when you open a new ui and have all the uis listen for it and check if they should close.

1 Like

This seems like you are making it so that it closes for every single person in the server.

I just want it to close for the local player.

You can simply loop through all the other UI’s and have their Visible Property set to false and add an if condition that matches the name and doesn’t do it for that specific UI.
As suggested by @FusionOak , You can simply fire a RemoteEvent if you’re detecting the click on the server (Fire the RemotEvent to the Player you want this change to reflect on) and have a callback of this on the Client to do something OR you can simply do the whole thing locally.

I want to tween the selected frame though.

You can do whatever you please with the frame. StarterGui is replicated on each client and as long as you’re making changes on the players PlayerGui, it should stay local

But how do I select the frame that needs to move? In your solution its just make everything else not visible

Have an if condition that looks for if item.Name == framename then continue end

Basically each frame should control itself. And when every frame is told to close, each frame should check that it wasn’t the one trying to close everything. That way everything but the correct one closes.

do this,

once a player opens their ui you set a value in your script called lastUI, but before you do this you check if it wasnt alrwady set. if this is the case there was a ui opend already. first you close this. then you set it to the new open ui.

this way there can never be more then 1 ui opend.

when you close the last ui. just set the variable to nil so it wont be closed twice.

EDIT:

example

‘’’
local lastUI = nil

function openUI(targetUI)

— if no ui is provided return
if targetUI == nil then
— if there was a last ui close it
if lastUI ~= nil then
lastUI.Visible = false
lastUI = nil
end
return
end

if lastUI then
lastUI.Visible = false
end

targetUI.Visible = true
lastUI = targetUI
end
‘’’

1 Like

Now the UI does not even open. Here is my script, I modified it a little bit so it can work in my environment.

local opened = false
local blur = game.Lighting.menublur
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)

local lastUI = nil
local targetUI = nil

script.Parent.MouseButton1Click:Connect(function()
	targetUI = script.Parent.Parent.Frame1
	if lastUI == nil then
		targetUI:TweenPosition(
			UDim2.new(1.1, 0, 0.065, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			1,
			true
		)
		lastUI = targetUI
	elseif lastUI then
		lastUI:TweenPosition(
			UDim2.new(1.1, 0, 0.065, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			1,
			true
		)
		targetUI:TweenPosition(
			UDim2.new(0.249, 0, 0.065, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			1,
			true
		)
		lastUI = targetUI
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	if opened == false then
		script.Parent.Parent.Frame1:TweenPosition(
			UDim2.new(0.249, 0, 0.065, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			1,
			true
		)
	elseif opened == true then
		script.Parent.Parent.Frame1:TweenPosition(
			UDim2.new(1.1, 0, 0.065, 0),
			Enum.EasingDirection.InOut,
			Enum.EasingStyle.Quad,
			1,
			true
		)
	end
end)