Roblox GetGuiObjectsAtPosition return nil

Here’s the script:

Mouse.Move:Connect(function()

local MousePos = UIS:GetMouseLocation() - game:GetService(“GuiService”):GetGuiInset()

local getGUI = plr:WaitForChild(“PlayerGui”):GetGuiObjectsAtPosition(MousePos.X,MousePos.Y)

print(getGUI.Name)

end)

And here’s the video: https://gyazo.com/11c17c33d60b462b28f2a0bb8afc59ee

1 Like

:GetGuiObjectsAtPosition() returns an array. Arrays don’t have a key ‘Name’, which is why your code prints nil. If the function returned nil, you would get an error `“Attempt to index nil with ‘Name’”. If you want to do something with the returned guiObjects, you’ll need a loop.

for i, guiObj in ipairs(getGui) do
    print(guiObj.Name)
end
1 Like

I mean it would return a table, a table isn’t nil

1 Like
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Move:Connect(function()
	local MousePos = game:GetService("UserInputService"):GetMouseLocation() - game:GetService("GuiService"):GetGuiInset()
	local getGUI = Player:WaitForChild("PlayerGui"):GetGuiObjectsAtPosition(MousePos.X,MousePos.Y)

	for _, GuiObject in pairs(getGUI) do
		print(GuiObject)
	end
end)
2 Likes

I though it return a gui, silly me