Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

2 comments

1

Coincidently, I'm working with gui's right now!

0

Thanks, this works!

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.