How to find closest guiobject to a frame

Really self explantory, how to find the closest guiobject to a frame? (There are more than 1 gui object)

What I would do is do an ipairs loop that goes through all of your GUI objects and get their positions. The next part is finding how far away the GUI object is, so bear with me on this one.

What you need to do is take the absolute value (math.abs) of the current gui X position minus the object’s X position. Then do the same thing for the Z position. Next, you need to use the pythagorean theorem (a^2+b^2=c^2) to try and find the distance. Since we are solving for the hypotenuse, we need to use the formula image to find the distance.

Finally before the pairs loop make a variable called Value and set it to math.huge. If a distance ends up being lower than maxValue, then set Value to the distance and make another variable called ClosestGui and set the name of the gui to this.

Let me know if you need any more help with this.

Ah, thanks for help, I’ll let you know.