Hello, I’m m having trouble with getting gui positions using; BasePlayerGui | Roblox Creator Documentation
And
https://developer.roblox.com/en-us/api-reference/event/GuiObject/MouseEnter
I’m not exactly sure how to use them. My goal is to see when a gui is created and what position it’s in, or what a player clicks on it what position it’s in, thanks.
If you’re talking about getting all the objects at the mouse position, then you can use the arguments of UserInputService:GetMousePosition()
to get the mouse position:
local UIS = game:GetService("UserInputService")
local BasePlayerGui = -- StarterGui, PlayerGui, CoreGui
local guisInPosition = BasePlayerGui:GetGuiObjectsAtPosition(
UIS:GetMouseLocation().X,
UIS:GetMouseLocation().Y
) -- Returns a table of all the objects at the mouse position
for _, GuiObject in ipairs(guisInPosition) do
print(GuiObject)
end
If you want to get the guis when the player clicks, then you just have to hook it up to a mouse connection:
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- run code to get guis at position
end
end)
Keep in mind that :GetMouseLocation()
only returns objects in that position with their Active property set to true.
1 Like
Looks like you forgot to call a function there
Ok so I did this but I get an error.
This is the script Im using:
local UIS = game:GetService("UserInputService")
local BasePlayerGui = game.StarterGui-- StarterGui, PlayerGui, CoreGui
local guisInPosition = BasePlayerGui:GetGuiObjectsAtPosition(
UIS:GetMousePosition(0, 0).X,
UIS:GetMousePosition(0, 0).Y
) -- Returns a table of all the objects at the mouse position
for _, GuiObject in ipairs(guisInPosition) do
print(GuiObject)
end
Error = GetMousePosition is not a valid member of UserInputService “Instance”
pretty sure he meant “GetMouseLocation”