Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I check if a GUI is at a position?

Asked by 9 years ago

I am trying to remember how to do it but WIKI is a mess and it's hard to find the information so I have tried to do this:

if GUI.Position == {0.2,0},{0,0} then

but it does not work!

Does anyone know the snippet to check GUI position?

2 answers

Log in to vote
0
Answered by 9 years ago

Gui Positions and Sizes are in UDim2 values. The format for them is like this UDim2.new(scaleX, offsetX, scaleY, offsetY)

If you wanted to check if the position was equal to something, you would have to create a UDim2 value to check it with:

if GUI.Position == UDim2.new(0.2, 0, 0, 0) then
    --do stuff
end

Since the Size and Position are the same type of value (UDim2) it'd be the same method for checking size as it is for position

if GUI.Size == UDim2.new(0, 100, 0 , 100) then

Hope this helped

1
Coincidently, I'm working with gui's right now! EzraNehemiah_TF2 3552 — 9y
0
Thanks, this works! Arithmeticity 167 — 9y
Ad
Log in to vote
0
Answered by 2 years ago

Ok, I know this was made 7 years ago, and this person probably doesn't even use Roblox or this site anymore, but I'm just posting my answer just in case anyone at present time comes across this problem and finds this.

What I did could probably be simplified but sometimes GUI positions ABSOLUTE position is different, and has decimals and what not. So I would clone the GUI and set the clones position to the position you think it's at and check with an "if" statement as so in the code.

local guiPositionCheck = GUI:Clone()

if GUI == guiPositionCheck.Position then
    guiPositionCheck:Destroy()
    --Your Code Here
end

I didn't set the clone position in the code, because I was lazy lol, but you can do that. Anyways hope this helps if anyone comes across this.

Answer this question