Know whatever GUI the Mouse is hovering

I do pcall because it’s faster (to code) than doing something that could know if it’s not a Gui object…

It’s not faster at all. All gui objects inherit from GuiObject. You can check if it’s a gui object with blah:IsA("GuiObject")

So… With that, I take the position and the size of ALL Gui Objects then find where the mouse is in?
Using the mouse’s coordinates
I also like to evoluate my comments :slight_smile: By adding text

GetGuiObjectsAtPosition takes an X and a Y. Not a UDim2.

1 Like

It can be UDim (1) but not in this case… It’s Vector2, so using X and Y is right :slight_smile:

I updated the code to use X and Y coordinates, so it should work by now… I think?

I didn’t saw that it return objects! I thought it return Vector2!

It works :slight_smile: And the operation method is very usefull since it returns all Gui Objects found
I answer in multi-posts, so… Sometimes I can answer from the fourth or else post

GetGuiObjectsAtPosition will return a table of the objects at a given position, if you were to access these objects, you must use

for i,v in ipairs(GUIs) do
    --code
end

I was allways trying to understand, WHAT IS ipairs() ? :thinking:
I never needed to use it :slight_smile: I think

ipairs() is used for indexing a table with number indexes, unlike pairs() is supposed to be used in dictionaries, but could also be used in regular tables. It just makes code analysing easier.

Correct
local Dictionary = {
    ["Iteration 1"] = "Value",
    ["Iteration 2"] = "Value"
}

for i,v in pairs(Dictionary) do
    print(i,v)
end

Output:

Iteration 1 Value
Iteration 2 Value

local Table = {Value,Value}

for i,v in ipairs(Table) do
    print(i,v)
end

Output:

1 Value
2 Value

Incorrect
local Dictionary = {
    ["Iteration 1"] = "Value",
    ["Iteration 2"] = "Value"
}

for i,v in ipairs(Dictionary) do
    print(i,v)
end
1 Like

:neutral_face:
I will find myself in the “Wiki”
:confused: I don’t understand:

Returns three values: an iterator function, and the table t .

It’s too much “sumarized”

Ok, with you I understand better! :smile: Why the Wiki is hard to understand on ipairs() ?

To let you know pcall just ignores errors.

I know, I used because it was fast to code :slight_smile:

What do you mean “fast to code”?

Like really fast to type?

For this, I mean fast to type! :smile:

It’s your choice but I will suggest you to don’t code like that.

I agree, it was to do a code that would work for the first time, it worked but it’s the “checker” which doesn’t work :slight_smile:

For anyone looking at this post in 2021 you can use Mouse.X and Mouse.Y instead of position
figured this out after trying this and the output showing that position is not a valid member of mouse

hopefully this helps someone out who’s trying to solve this! :smile:

1 Like

Yeah and also it is PlayerGui, not StarterGui