GetGuiObjectsAtPosition not seeing Gui

Hi,

I’m having issues using GetGuiObjectsAtPosition(). It’s a strange problem I’m having because it sometimes detects my Gui but usually doesn’t.

This is my code:

local UserInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		local location = UserInputService:GetMouseLocation()
		local GuiObjects = playerGui:GetGuiObjectsAtPosition(location.X, location.Y)
		
        --Used to display red dots where I click for debugging
		local testScreen = Instance.new("ScreenGui", playerGui)
		testScreen.IgnoreGuiInset = true
		local test = Instance.new("Frame", testScreen)
		test.Size = UDim2.new(0, 5, 0, 5)
		test.Position = UDim2.new(0, location.X, 0, location.Y)
		test.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		
		print(GuiObjects)
	end
end)

The following video shows the game running and how it only sometimes recognizes the Gui.

Thanks in advance for any help.

If I’m right, I think GetGuiObjects ignores inset, but the input position doesn’t, so if you -36 to the Y input position maybe it’ll work, though to be honest I’m not 100% because I wouldn’t normally use this method.

1 Like