Comparing Udim2 value's

while true do
	wait(1)
	script.Parent.Size = script.Parent.Size - UDim2.new(0.2,0,0,0)
	if script.Parent.Size <= UDim2.new(1.172, 0,0.52, 0) then
		
		break
	
		
	end
end


Why does this come up with an error?

1 Like

Could you tell us what the error is? Also, is this a local script for a GUI?

2 Likes

This is the error: Players.littlestuffin.PlayerGui.UI.TL.hungerimg.bar.LocalScript:4: attempt to compare userdata

And yes, It is a local script for a GUI.

1 Like

To compare positions, I think you may need to manually check each individual property of the UDim2.

4 Likes

You can’t actually compare UDim2 values because they are table values. You would be better off comparing the actual values using the .Y value and the .X value. I had this issue a few days ago and this is the code I came up with that worked (I’m only comparing the Y value here but hopefully you will get the idea!

	for _, v in pairs (script.Parent.Frame:GetChildren())do
		spawn(function()
			if v:IsA("TextLabel")and v.Name == 'Template'then
				if v.Position.Y.Offset > 200  then
					v:Destroy()
				else
					local newpo = v.Position.Y.Offset + 20
					v.Position = UDim2.new(0,0,0,newpo)
				end
			end
		end)
	end	
1 Like

Hello, thank you for answering my problem. I would give you the solution thing, however Haukly said it first lol.

I don’t think comparison operators are allowed for UDim2s. Like what @topdog_alpha and @Haukly said, you may find more luck comparing the individual properties of the UDim2.

   if script.Parent.Size.X.Scale <= 1.172 and script.Parent.Size.Y.Scale <= 0.52 then
      --stuff
   end
1 Like

UDim2 is not a table, it is an object with properties. It can be created from the UDim2 class and it’s also considered a datatype. Although tables are objects as well, there’s a distinct difference between them and UDim2.

1 Like