How to compare UDim and UDim2 value's

I was trying to make a gui where you let go of the button to stop the tween on a certain position. to have a higher chance to get something. But I get an error “attempt to compare UDim” or “attempt to compare UDim2”.

-- Local script
-- the script's parent is the screen gui.
local moveframe = script.Parent.Border.ShotMeter.Target.Mover
local borderup = script.Parent.Border.ShotMeter.Target.BorderTagUp
local borderdown = script.Parent.Border.ShotMeter.Target.BorderTagDown

PauseShot.OnClientEvent:Connect(function(player)
	createanim:Cancel()
-- where the error occurs with both UDim and UDim2.
	if moveframe.Position.Y <= borderup.Position.Y and moveframe.Position.Y >= borderdown.Position.Y then
		print("!!green!!")
	end
	wait(0.4)
	moveframe.Position = UDim2.new(0.469,0 ,2.475, 0)
end)

You forgot to index Y property of the value.
moveframe.Position.Y

I saw my mistake but It still did not work.

UDim2 is made of 2 UDim values. If you need to compare the Scale then do if position.Y.Scale >= position2.Y.Scale, etc

1 Like

Alternatively, you can use AbsolutePosition properties of the values instead of Position.

Tried that but it won’t work and I am not trying to compare the size.

Well my guess is that u cant compare Udim2 value as an int value. I would try to compare it like that: frame. Poition. Y. Offset (or Scale, idk what are u using). And then u have two int values to compare

What do you mean? Scale isn’t exclusively for size.

I tried it and it has no error but now it won’t print. Never mind I had comparisons signs inverted.