:TweenSizeAndPosition results in rigid movement

I’m writing a very simple function that shrinks a GUI element and then restores it to its original size afterward, while also keeping the center of the GUI the same. However, I noticed that the movement wasn’t as smooth as I’d like it to be. I slowed it down and realized that the resizing was rigid.

Here’s the code that handles this:

currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset - 8, 0, currentSelection.Size.Y.Offset - 8), UDim2.new(0.5, currentSelection.Position.X.Offset + 4, 0.5, currentSelection.Position.Y.Offset + 4), "In", "Linear", 5)
wait(5)
currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset + 8, 0, currentSelection.Size.Y.Offset + 8), UDim2.new(0.5, currentSelection.Position.X.Offset - 4, 0.5, currentSelection.Position.Y.Offset - 4), "Out", "Linear", 5)

Am I doing something wrong? Is this just the natural behavior of tweening? Is there anything I can do to get smooth movement? Thanks.

1 Like

The issue might just come down to how small the movement is. Since the overall size is only changing by 4 pixels in every direction, there are only 4 logical “steps” that can be shown throughout the tween. A simple way to make it appear more snappy is to make the duration really short or to make the change more dramatic.

This version happens really fast:

currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset - 8, 0, currentSelection.Size.Y.Offset - 8), UDim2.new(0.5, currentSelection.Position.X.Offset + 4, 0.5, currentSelection.Position.Y.Offset + 4), "In", "Linear", .4)
wait(5)
currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset + 8, 0, currentSelection.Size.Y.Offset + 8), UDim2.new(0.5, currentSelection.Position.X.Offset - 4, 0.5, currentSelection.Position.Y.Offset - 4), "Out", "Linear", .4)

This version makes a larger movement:

currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset - 40, 0, currentSelection.Size.Y.Offset - 40), UDim2.new(0.5, currentSelection.Position.X.Offset + 20, 0.5, currentSelection.Position.Y.Offset + 20), "In", "Linear", 5)
wait(5)
currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset + 40, 0, currentSelection.Size.Y.Offset + 40), UDim2.new(0.5, currentSelection.Position.X.Offset - 20, 0.5, currentSelection.Position.Y.Offset - 20), "Out", "Linear", 5)

This version is a combination of both:

currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset - 20, 0, currentSelection.Size.Y.Offset - 20), UDim2.new(0.5, currentSelection.Position.X.Offset + 10, 0.5, currentSelection.Position.Y.Offset + 10), "In", "Linear", .6)
wait(5)
currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset + 20, 0, currentSelection.Size.Y.Offset + 20), UDim2.new(0.5, currentSelection.Position.X.Offset - 10, 0.5, currentSelection.Position.Y.Offset - 10), "Out", "Linear", .6)
1 Like

Or you can make it so simple to write 0.1 pixel in the script and not 4 pixels so the picture or that or other object will move much smoother

Сводка

currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset - 8, 0, currentSelection.Size.Y.Offset - 20), UDim2.new(0.5, currentSelection.Position.X.Offset + 0.1, 0.5, currentSelection.Position.Y.Offset + 0.1), “In”, “Linear”, .3)
wait(5)
currentSelection:TweenSizeAndPosition(UDim2.new(0, currentSelection.Size.X.Offset + 8, 0, currentSelection.Size.Y.Offset + 20), UDim2.new(0.5, currentSelection.Position.X.Offset - 0.1, 0.5, currentSelection.Position.Y.Offset - 0.1), “Out”, “Linear”, .3)

You can’t adjust an object’s size/position by a fraction of a pixel, Roblox will just round it to the nearest whole number before rendering. A pixel is a physical limitation of resolution, so there’s no way to represent something “in-between” pixels (without getting into the topic of subpixel rendering, which is an entirely different conversation and not something Roblox supports for GUIs).