Attempt to compare UDim2 <= UDim2

I’m trying to compare 2 UDim2 values to check if one is smaller than the other, however this is not working. All help is appreciated.

while wait() do
	script.Parent.MiddleBar.SurfaceGui.CallingAt.Position =, 0, 0, 0)
		script.Parent.MiddleBar.SurfaceGui.CallingAt.Position = script.Parent.MiddleBar.SurfaceGui.CallingAt.Position -, 0, 0, 0)
	until script.Parent.MiddleBar.SurfaceGui.CallingAt.Position <=, 0, 0, 0)

I think comparing UDim values isn’t possible. A solution would be to write your own function that breaks the UDim into it’s x, y components and compare them individually(that way you have control over how the comparison is made).

Also most of the time you don’t have to compare UDim or Color3 values because they can be broken down into smaller problems with easier solutions, for example:

local CallingAt = script.Parent.MiddleBar.SurfaceGui.CallingAt
while task.wait() do
	CallingAt.Position =, 0, 0, 0)
		CallingAt.Position -=, 0, 0, 0)
	--only check the scale x, since you are only changing that
	until CallingAt.Position.X.Scale <= -1
1 Like

You can’t compare UDim2 values because they are table values. You need compare each component seperately:

until script.Parent.MiddleBar.SurfaceGui.CallingAt.Position.X.Scale<=-1