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 By adding text
GetGuiObjectsAtPosition
takes an X and a Y. Not a UDim2.
It can be UDim (1) but not in this case… It’s Vector2, so using X and Y is right
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 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() ?
I never needed to use it 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
…
I will find myself in the “Wiki”
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! 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
What do you mean “fast to code”?
Like really fast to type?
For this, I mean fast to type!
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
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!
Yeah and also it is PlayerGui, not StarterGui